DDL语句
更新时间:2021-02-18
CREATE TABLE
语法
CREATE TABLE tableName (
column_name datatype[,column_name datatype]
)WITH(
property_name=property_value [, property_name=property_value]
);
- 创建的表仅作用于当前作业,同一作业中表名称不可相同,不同作业中创建的表名称可以相同。
- DDL语法中关键字、表名、列名等不区分大小写。
- 表名、列名必须以字母或者数字开头,表名、列名中只能包含字母、数字、下划线。
- with参数必须包含type参数来指明存储的类型
创建百度消息队列(kafka)表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | 输入端接入的数据资源的类型,百度智能云kafka的类型值为BKAFKA |
topic | string | 是 | BKAFKA中用户自己创建的Topic |
kafka.bootstrap.servers | string | 是 | BKAFKA服务器地址和端口,地址和端口之间用“:”分隔。例如:kafka.baidu.com:9092 |
sslFilePath | string | 是 | 该topic的证书文件,格式为zip |
encode | string | 是 | Kafka中数据的编码格式,支持json和csv格式的消息 |
startingOffsets | int | 否 | 指定起始消费的offset,可填值为:earliest、latest |
failOnDataLoss | string | 否 | 数据丢失后是否报错,可填值为:true、false,默认值true |
columnDelimiter | string | 否 | 列分隔符 |
lineDelimiter | string | 否 | 行分隔符 |
-
对于Json格式的消息,只支持将Json记录的第一层的key定义为列名。
例如,schema为{“key1”:string,“key2”:int,“key3”:{“key4”:“string,”key5“:string}}的Json,需要将Table的列定义为(key1 string,key2 string,key3 string)。
- 通过json_tuple、get_json_object、to_json、from_json等函数对Json格式数据进行处理。
创建RDS类型数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | 输入端接入的数据资源的类型,此处填写“RDS” |
user | string | 是 | RDS的用户名 |
password | string | 是 | RDS用户名对应的密码 |
url | string | 是 | 通过jdbc访问rds的url,例如 jdbc:mysql://mysql56.rdsmiusj9oseag6.rds.bj.baidubce.com:3306/bsc_test |
dbTable | string | 是 | 数据表名称 |
创建TSDB数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | TSDB的类型值为”TSDB” |
tsdbUrl | string | 是 | tsdb访问地址 |
accountId | string | 是 | 用户的accountId买书 |
readTimeoutMs | int | 否 | HttpClient请求的超时时间 |
maxConnectionTotal | int | 否 | HttpClient的连接池最大连接数 |
maxConnectPerRoute | int | 否 | HttpClient的每个路由最大连接数 |
isBatch | string | 否 | 是否使用batch方式写tsdb,可填字符串为true、false |
maxRecordsPerBatch | int | 否 | 使用batch方式,一次POST的最大记录个数,isBatch为true时有效 |
maxByteSizePerBatch | int | 否 | 使用batch方式,一次POST的最大字节数,isBatch为true时有效 |
另外,TSDB作为目的端的DML SQL语句示例如下:
insert into
sink_table_tsdb(integertype)
select
to_json(
named_struct(
'datapoints',
array(
named_struct(
'metric', 'intergertype',
'timestamp', max(source_table_kafka.timestamp),
'value', count(integertype),
'tags', map('booleantype', 'true')
)
)
)
)
from
source_table_kafka
group by
source_table_kafka.bytetype ;
创建MQTT数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | MQTT的类型值为”MQTT” |
brokerUrl | string | 是 | 订阅的mqtt的broker的url地址 |
topic | string | 是 | 需要订阅的topic |
username | string | 否 | 如果broker的访问需要用户名、密码,就设置 |
password | string | 否 | 如果broker的访问需要用户名、密码,就设置 |
connectionTimeout | int | 否 | 访问超时时间设置,默认30秒 |
keepAliveInterval | int | 否 | 保持连接的时长,连接长时间不活动后,会被断开,默认60秒 |
maxBatchMessageNum | int | 否 | 每个batch最大数据条数,默认值Int.Max |
maxBatchMessageSize | int | 否 | 每个batch最大消息字节数,默认值Int.Max |
创建百度智能云BOS数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | BOS的类型值为”BOS” |
path | string | 是 | 数据需要写出的BOS的路径,需要以bos://开头 |
encode | string | 是 | 数据的编码格式,支持json和csv格式的消息 |
创建ES数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | ES的类型值为”ES” |
es.net.http.auth.user | string | 是 | es集群用户名,百度智能云ES默认用户名为superuser |
es.net.http.auth.pass | string | 是 | es集群用户密码 |
es.clusterId | string | 是 | es集群的id |
es.region | string | 是 | es集群所在region,例如:bd,bj,gz等 |
es.port | int | 是 | 如果es.nodes中的Node没有指定port, 则使用该值作为默认值 |
es.resource | string | 是 | 指定要访问的index type |
es.version | string | 否 | 访问Es集群的版本号,默认5.5.0 |
创建Redis数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | redis的类型值为” REDIS” |
key.column | string | 是 | 用户需指定结果表中一列作为redis key;用户所指定的列名 |
key.ttl | string | 否 | redis key的失效时间 |
redis.auth | string | 否 | redis服务密码 |
redis.db | string | 否 | 所选的redis库;默认值0 |
redis.host | string | 是 | redis服务地址;默认值localhost |
redis.port | int | 是 | redis服务端口;默认值6379 |
redis.timeout | int | 否 | redis连接的超时时间;默认值2000 |
创建Palo数据表
with参数说明
参数名称 | 数据类型 | 必填 | 描述 |
---|---|---|---|
type | string | 是 | 类型值为” PALO” |
clusterId | string | 是 | 百度智能云palo集群id |
region | string | 是 | palo集群所属的区域,例如:bd,bj, gz等 |
username | string | 是 | 访问palo集群的用户名,例如:admin |
password | string | 是 | 访问palo集群的密码 |
database | string | 是 | 数据库名称 |
table | string | 是 | 数据表名称 |
mysqlPort | string | 否 | mysql连接使用的端口号,默认值9030 |
computePort | string | 否 | 连接compute Node使用的端口号,默认值8040 |