阿里云Flink sql 基本使用手册

以下操作全部按照阿里云官方文档整理。

参考文档参考 实时计算Flink版 - 帮助中心 - 阿里云https://help.aliyun.com/product/45029.html

1 维度表

        

CREATE TEMPORARY TABLE datahub_source (
  `goods_id` String,
  `goods_name` String,
  `goods_category` String,
  `goods_price` String,
  `etl_time` BIGINT
) WITH (
  'connector' = 'datahub',
  'subId' = 'xxxx',
  'endPoint' = 'https://dh-cn-shanghai.aliyuncs.com',
  'project' = 'xxxx',
  'topic' = 'xxxx',
  'accessid' = 'xxxx',
  'accesskey' = 'xxxx',
  'startTime' = '2022-01-20 17:57:00'
);

create TEMPORARY table odps_dim(
  ategory_id VARCHAR,
  ategory_name VARCHAR,
  PRIMARY KEY (ategory_id) not enforced
) with (
  'connector' = 'odps', 
  'endpoint' = 'http://service.cn.maxcompute.aliyun.com/api',
  --'tunnelEndpoint' = 'http://service.cn.maxcompute.aliyun.com/api', 全托管 
  'project' = 'xxxx',
  'tablename' = 'xxxx',
  'accessid' = 'xxxxxxxxxxxxxxxx',
  'accesskey' = 'xxxxxxxxxxxxxxxx',
  'partition' = 'ds=20220119',
  'cache' = 'ALL',
  'cacheSize' = '10',  -- 目前维度表只有4条数据,生产使用的时候size需要大于实际条数
  'cacheTTLMs' = '180000' --3分钟 = 180000ms 数据缓存时间,多久更新一次
);

CREATE TEMPORARY TABLE print_sink (
  `goods_category` VARCHAR,
  `goods_category_name` VARCHAR
) WITH (
  'connector' = 'print'
);

BEGIN statement set;
insert into print_sink
select 
    ategory_id,
    ategory_name
from 
datahub_source
left join odps_dim FOR SYSTEM_TIME AS OF PROCTIME() as h 
on goods_category=ategory_id ;
END;


2    视图

create TEMPORARY table odps_source(
  ategory_id VARCHAR,
  ategory_name VARCHAR
) with (
  'connector' = 'odps', 
  'endpoint' = 'http://service.cn.maxcompute.aliyun.com/api',
  --'tunnelEndpoint' = 'http://service.cn.maxcompute.aliyun.com/api', 全托管一定不要加
  'project' = 'xxxx',
  'tablename' = 'xxxx',
  'accessid' = 'xxxx',
  'accesskey' = 'xxxx',
  'partition' = 'ds=20220119'
);

create TEMPORARY VIEW odps_source_view as
select 
    ategory_id,
    ategory_name 
from odps_source 
where cast(ategory_id as bigint) > 2;

create TEMPORARY table odps_sink(
  ategory_id VARCHAR,
  ategory_name VARCHAR
) with (
  'connector' = 'print'
);

BEGIN statement set;
insert into odps_sink
select * from odps_source_view ;
END;


3    滚动窗口

CREA

你可能感兴趣的:(互联网,阿里云,flink,sql,blink,大数据)