【问题标题】:Using LIKE to compare two columns in SPARK SQL使用 LIKE 比较 SPARK SQL 中的两列
【发布时间】:2017-01-04 13:43:10
【问题描述】:

我有两个 SPARK SQL 表如下,

表 1

email           |  client_ip    |  travelling_method | travelling_code
person1@abc.com |203.22.22.22   | Car                | car001
person1@abc.com |203.22.22.22   | Jeep               | jeep001              

表2

email           |  client_ip    |  account_type | trav_code
person1@abc.com |203.22.22.22   | true          | car
person1@abc.com |203.22.22.22   | false         | jeep  

我的查询如下,

SELECT table1.email, table1.client_ip, table1.travelling_method, table1.travelling_code, table2.account_type FROM table1 LEFT JOIN table2 ON table1.email = table2.email AND table1.client_ip = table2.client_ip AND table1.travelling_code LIKE CONCAT('%' ,table2.trav_code, '%') WHERE table1.email = 'person1@abc.com';

我编写了上面的查询以获得以下输出,但它抛出了一个异常。

想要的输出是:

email           |  client_ip    |  travelling_method | travelling_code| account_type
person1@abc.com |203.22.22.22   | Car                | car001         | true
person1@abc.com |203.22.22.22   | Jeep               | jeep001        | false

感谢有人可以帮助我指出我的查询中缺少什么。 :)

【问题讨论】:

  • 你能再添加一个错误堆栈吗?你能用查询的最后一个和在哪里替换吗

标签: apache-spark apache-spark-sql spark-dataframe wso2-das


【解决方案1】:

试着在合适的地方写“where”,比如

SELECT table1.email, table1.client_ip, table1.travelling_method, table1.travelling_code, table2.account_type 
 FROM table1 LEFT JOIN table2 ON table1.email = table2.email WHERE 
 table1.client_ip = table2.client_ip 
 AND table1.travelling_code LIKE CONCAT('%' ,table2.trav_code, '%') and table1.email = 'person1@abc.com'

我没有测试您的查询。如果仍然遇到错误,请发布错误消息。

【讨论】:

  • 我试过你的查询,但它仍然抛出一个错误:AnalyticsProcessorAdminServiceAnalyticsProcessorAdminExceptionException。
猜你喜欢
  • 2018-11-14
  • 2020-06-07
  • 1970-01-01
  • 2020-02-26
  • 2023-03-22
  • 1970-01-01
  • 2017-10-24
  • 1970-01-01
  • 2022-12-16
相关资源
最近更新 更多