数据描述:
head和detail表在doris中均以bill_date作为分区字段。
问题描述:
spark doris connector支持在doris端实现数据过滤,通过使用query.filter参数。
我在spark代码连接两张doris数据源:head和detail,均过滤出2023-03数据,这两个临时表使用count(*)时head 有1条数据、detail有2条数据;这些都是可以在spark webUI可以看到数据源是过滤的;
但是当执行head和detail join时,head和detail均又变成了全表扫描,但是在spark中过滤bille_date=2023-03的数据,又起不到分区查询的目的。
以下为相关代码:
sc.sql(
s"“”
| create or replace temporary view d
| using doris
| options(
| “table.identifier”=“shdw.ods_jxc_sal_meet_detail”,
| “fenodes”=“xx.xx.xx.xx:8030”,
| “user”=“xxxx”,
| “password”=“xxxx”,
| “doris.request.connect.timeout.ms”=“600000”,
| “doris.request.read.timeout.ms”=“600000”,
| “doris.filter.query” = “bill_date >= ‘2023-03-01’ and bill_date <= ‘2023-03-31’”
| )
“”".stripMargin)
sc.sql(
s"""
| create or replace temporary view h
| using doris
| options(
| "table.identifier"="shdw.ods_jxc_sal_meet_head",
| "fenodes"="xx.xx.xx.xx:8030",
| "user"="xxxx",
| "password"="xxxx",
| "doris.request.connect.timeout.ms"="600000",
| "doris.request.read.timeout.ms"="600000",
| "doris.filter.query" = "bill_date >= '2023-03-01' and bill_date <= '2023-03-31'"
| )
""".stripMargin)
sc.sql(
"""
| select count(*) from h
""".stripMargin
).show()
±-------+
|count(1)|
±-------+
| 1|
±-------+
sc.sql(
"""
| select count(*) from d
""".stripMargin
).show()
±-------+
|count(1)|
±-------+
| 2|
±-------+
sc.sql(
"""
|SELECT
| h.db_id,
| h.enterprise_id,
| h.hand_employee_id,
| h.hand_employee_name,
| d.item_code,
| d.item_name,
| h.bill_date
|FROM d
|INNER JOIN h
|ON h.db_id =d.db_id
| AND h.enterprise_id = d.enterprise_id
| AND h.bill_id = d.bill_id
""".stripMargin).show()
±---------+
| bill_date|
±---------+
|2019-09-09|
|2019-11-18|
|2019-11-18|
|2019-12-21|
|2019-12-21|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2020-09-16|
|2019-12-06|
|2019-12-06|
|2019-12-06|
|2019-12-06|
|2019-12-06|
|2019-12-06|
±-----±------------±---------------±-----------------±--------±-------------------------------±---------+