我正在使用 Java 语言。我的代码中包含以下查询内容:
public static String GET_E_BCHGS = "SELECT BCL.* "
+"FROM (SELECT * "
+"FROM (SELECT (SELECT BILLABLE_CHG_ID "
+"FROM BC "
+"WHERE BC.BILLABLE_CHG_STAT = 10 "
+"AND BC.FEED_SOURCE_FLG = 'TFM' "
+" AND BC.SA_ID = S.SA_ID AND (EXISTS (SELECT 1 "
+"FROM BCC "
+"WHERE BCC.BILLABLE_CHG_ID = BC.BILLABLE_CHG_ID "
+"AND BCC.CHAR_TYPE_CD = 'AGG_CRTA' "
+"AND BCC.ADHOC_CHAR_VAL = S.SID) "
+"OR "
+"(BC.PRICEITEM_CD = S.FIN_PRICEITEM_CD "
+"AND BC.TOU_CD =S.TOU_CD "
+"AND BC.START_DT =S.BCHG_START_DT "
+"AND BC.END_DT =S.BCHG_END_DT "
+"AND BC.PRICE_ASGN_ID= S.PRICE_ASGN_ID "
+"AND BC.PRICEITEM_PARM_GRP_ID = S.PRICEITEM_PARM_GRP_ID "
+"AND BC.AGG_PARM_GRP_ID = S.AGG_PARM_GRP_ID) "
+") AND NOT EXISTS (SELECT 1 "
+"FROM C, BS "
+"WHERE BS.bseg_id = C.bseg_id "
+"AND C.billable_chg_id = BC.BILLABLE_CHG_ID "
+"AND BS.bseg_stat_flg not in (10,60))) "
+"AS BILLABLE_CHG_ID "
+"FROM S "
+"WHERE SID >= '2100000000063000004222017020100018243020717805750011' "
+"AND SID <= null "
+"AND "
+"STATUS = ' ' "
+"AND TXN_RATING_CRITERIA ='RITA') "
+"WHERE BILLABLE_CHG_ID <> ' ' "
+"GROUP BY BILLABLE_CHG_ID) F, BCL "
+"WHERE F.BILLABLE_CHG_ID = BCL.BILLABLE_CHG_ID "
+"ORDER BY BCL.BILLABLE_CHG_ID, LINE_SEQ";
我试图在Spark SQL中使用相同的代码,以下是相同的代码:
Dataset<Row> bc = sparkSession.read().format("jdbc").option("url",connection ).option("dbtable", "B_CHG").load();
bc.createOrReplaceTempView("BC");
Dataset<Row> bcc = sparkSession.read().format("jdbc").option("url",connection ).option("dbtable", "B_CHG_CHAR").load();
bcc.createOrReplaceTempView("BCC");
Dataset<Row> c = sparkSession.read().format("jdbc").option("url",connection ).option("dbtable", "B_CALC").load();
c.createOrReplaceTempView("C");
Dataset<Row> bs = sparkSession.read().format("jdbc").option("url",connection ).option("dbtable", "BSEG").load();
bs.createOrReplaceTempView("BS");
Dataset<Row> s = sparkSession.read().format("jdbc").option("url",connection ).option("dbtable", "TXN_DTL_P_SUMMARY").load();
s.createOrReplaceTempView("S");
Dataset<Row> bcl = sparkSession.read().format("jdbc").option("url",connection ).option("dbtable", "B_CHG_L").load();
bcl.createOrReplaceTempView("BCL");
Dataset<Row> existingBchgsDS = sparkSession.sql(SQQueries.GET_E_BCHGS);
existingBchgsDS.show();
在运行此代码时,出现以下错误:
Exception in thread "main" org.apache.spark.sql.AnalysisException: cannot resolve '`S.SID`' given input columns: [bcc.CHAR_VAL_FK4, bcc.CHAR_VAL_FK2, bcc.CHAR_VAL_FK5, bcc.BILLABLE_CHG_ID, bcc.ADHOC_CHAR_VAL, bcc.CHAR_VAL_FK3, bcc.CHAR_TYPE_CD, bcc.SRCH_CHAR_VAL, bcc.CHAR_VAL_FK1, bcc.CHAR_VAL, bcc.VERSION, bcc.EFFDT]; line 1 pos 297;
'Sort ['BCL.BILLABLE_CHG_ID ASC NULLS FIRST, 'LINE_SEQ ASC NULLS FIRST], true.........
//more lines of error
我想了解:
Spark SQL是否支持此类查询?
或
还有其他写方法吗?
火花版本:2.3.0
答案 0 :(得分:0)
我认为您的操作是正确的,您可以写sparkSession.sql()
,因为错误状态我认为在应用所有其他方法后无法找出column SID
中的Dataset S
条件,我认为最好让我们理解是否也可以发布数据集的架构。
是的,但是我建议在数据集上使用过滤器,select和other,这样您就可以更好地控制代码。 主要变化是简化了编码和调试。使用spark.sql,在编译时您不会有任何有关错误或键入错误的信息...并且使用.filter,.select更容易缩进,读取等...并且它具有相同的性能。