实时计算的join和传统批处理join的语义一致,都用于两张表之间的的join(例如,table a join table b
)。不同的是实时计算的table a
和table b
是两张动态表,join的结果也会动态更新以保证最终结果和批处理的一致性。
语法
tableReference [, tableReference ]* | tableexpression
[ LEFT ] JOIN tableexpression [ joinCondition ];
说明:
- 只支持等值连接, 不支持不等连接。
- 只支持inner join和left outer join两种
注意:DDL声明的字段、主键等要和真实表里面定义的一致。
示例一
测试语句
SELECT o.rowtime, o.productId, o.orderId, o.units,
p.name, p.unitPrice
FROM Orders AS o
JOIN Products AS p
ON o.productId = p.productId;
查询结果
rowtime |
productId |
orderId |
units |
name |
unitPrice |
10:17:00 |
30 |
5 |
4 |
Cheese |
17 |
10:17:05 |
10 |
6 |
1 |
Beer |
0.25 |
10:18:05 |
20 |
7 |
2 |
Wine |
6 |
10:18:07 |
30 |
8 |
20 |
Cheese |
17 |
11:02:00 |
10 |
9 |
6 |
Beer |
0.25 |
11:04:00 |
10 |
10 |
1 |
Beer |
0.25 |
11:09:30 |
40 |
11 |
12 |
Bread |
100 |
11:24:11 |
10 |
12 |
4 |
Beer |
0.25 |
示例二
测试数据
datahub_stream1:
a(bigint) |
b(bigint) |
c(VARCHAR) |
0 |
10 |
test11 |
1 |
10 |
test21 |
datahub_stream2:
a(bigint) |
b(bigint) |
c(VARCHAR) |
0 |
10 |
test11 |
1 |
10 |
test21 |
0 |
10 |
test31 |
1 |
10 |
test41 |
测试语句
create table datahub_stream1 (
a int,
b int,
c varchar
) WITH (
type='datahub',
endpoint='',
accessId='',
accessKey='',
projectName='',
topic='',
project=''
);
create table datahub_stream2 (
a int,
b int,
c varchar
) WITH (
type='datahub',
endpoint='',
accessId='',
accessKey='',
projectName='',
topic='',
project=''
);
create table rds_output(
s1_c varchar,
s2_c varchar
)with(
type='rds',
url='jdbc:mysql://XXXXXXX3306/test',
tableName='udf',
userName='tXXXXt',
password='XXXX6'
);
insert into rds_output
select
s1.c,s2.c
from datahub_stream1 AS s1
join datahub_stream2 AS s2 on s1.a =s2.a
where s1.a = 0;
测试结果
s1_c(varchar) |
s2_c(varchar) |
test1 |
test11 |
test1 |
test31 |