glibc的几个有用的处理二进制位的内置函数

— Built-in Function:  int __builtin_ffs (unsigned int x)

Returns one plus the index of the least significant 1-bit of x, or if x is zero, returns zero.
返回右起第一个‘1’的位置。

— Built-in Function:  int __builtin_clz (unsigned int x)

Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
返回左起第一个‘1’之前0的个数。

— Built-in Function:  int __builtin_ctz (unsigned int x)

Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
返回右起第一个‘1’之后的0的个数。

— Built-in Function:  int __builtin_popcount (unsigned int x)

Returns the number of 1-bits in x.
返回‘1’的个数。

— Built-in Function:  int __builtin_parity (unsigned int x)

Returns the parity of x, i.e. the number of 1-bits in x modulo 2.
返回‘1’的个数的奇偶性。

— Built-in Function: int __builtin_ffsl (unsigned long)

Similar to __builtin_ffs, except the argument type is unsigned long. 

— Built-in Function: int __builtin_clzl (unsigned long)

Similar to __builtin_clz, except the argument type is unsigned long. 

— Built-in Function: int __builtin_ctzl (unsigned long)

Similar to __builtin_ctz, except the argument type is unsigned long. 

— Built-in Function: int __builtin_popcountl (unsigned long)

Similar to __builtin_popcount, except the argument type is unsigned long. 

— Built-in Function: int __builtin_parityl (unsigned long)

Similar to __builtin_parity, except the argument type is unsigned long. 

— Built-in Function: int __builtin_ffsll (unsigned long long)

Similar to __builtin_ffs, except the argument type is unsigned long long. 

— Built-in Function: int __builtin_clzll (unsigned long long)

Similar to __builtin_clz, except the argument type is unsigned long long. 

— Built-in Function: int __builtin_ctzll (unsigned long long)

Similar to __builtin_ctz, except the argument type is unsigned long long. 

— Built-in Function: int __builtin_popcountll (unsigned long long)

Similar to __builtin_popcount, except the argument type is unsigned long long. 

— Built-in Function: int __builtin_parityll (unsigned long long)

Similar to __builtin_parity, except the argument type is unsigned long long.

来源: 点击打开链接
### 使用 Flink SQL 连接和操作 ClickHouse 数据库 #### 创建 Maven 或 Gradle 项目并配置依赖项 为了使 Apache Flink 能够连接到 ClickHouse 并执行查询,需要引入必要的 JDBC 驱动程序以及 Flink 的相关模块。对于 Maven 用户来说,在 `pom.xml` 文件中添加如下依赖: ```xml <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-connector-jdbc_2.12</artifactId> <version>${flink.version}</version> </dependency> <!-- Add the ClickHouse JDBC driver --> <dependency> <groupId>ru.yandex.clickhouse</groupId> <artifactId>clickhouse-jdbc</artifactId> <version>0.3.2</version> </dependency> ``` 上述代码片段展示了如何通过 Maven 来管理项目的外部库文件。 #### 定义表结构与注册数据源 在启动应用程序之前,应该先定义好要处理的数据模式,并将其映射成 Flink 中的逻辑表。这可以通过编写 DDL (Data Definition Language) 声明来完成: ```sql CREATE TABLE clickhouse_table ( id BIGINT, name STRING, age INT, PRIMARY KEY(id) NOT ENFORCED ) WITH ( 'connector' = 'jdbc', 'url' = 'jdbc:clickhouse://localhost:8123/default', 'table-name' = 'users' ); ``` 这段 SQL 语句创建了一个名为 `clickhouse_table` 的虚拟表,它指向了位于本地主机上的 ClickHouse 实例中的实际物理表 users[^1]。 #### 编写简单的 Flink 应用程序读取 ClickHouse 表 下面是一个完整的 Java 程序例子,该程序会从上面提到过的 ClickHouse 表里获取记录并将它们打印出来: ```java import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; public class ReadFromClickHouse { public static void main(String[] args) throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); String createDDL = "CREATE TABLE clickhouse_table (" + "id BIGINT,"+ "name STRING,"+ "age INT"+ ") WITH ("+ "'connector'='jdbc'," + "'url'='jdbc:clickhouse://localhost:8123/default'," + "'driver'='ru.yandex.clickhouse.ClickHouseDriver'," + "'username'='default'," + "'password'=''"+ ")"; tableEnv.executeSql(createDDL); Table result = tableEnv.sqlQuery( "SELECT * FROM clickhouse_table" ); // Convert to DataStream and print results. tableEnv.toAppendStream(result, Row.class).print(); env.execute("Read from ClickHouse"); } } ``` 此段代码实现了基本的功能——即建立至目标数据库的链接、构建相应的 Schema 描述符、发起 SELECT 查询请求最后输出检索所得的结果集[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值