public static Pair<List<List<String>>, List<SelectedColumnMeta>> tryPushDownSelectQuery(String project, String sql, String defaultSchema, SQLException sqlException, boolean isPrepare) throws Exception { return tryPushDownQuery(project, sql, defaultSchema, sqlException, true, isPrepare); }
private Pair<List<List<String>>, List<SelectedColumnMeta>> pushDownQuery(SQLRequest sqlRequest, String correctedSql, Connection conn, SQLException sqlException) throws Exception { try { return PushDownUtil.tryPushDownSelectQuery(sqlRequest.getProject(), correctedSql, conn.getSchema(), sqlException, BackdoorToggles.getPrepareOnly()); } catch (Exception e2) { logger.error("pushdown engine failed current query too", e2); //exception in pushdown, throw it instead of exception in calcite throw e2; } }
if (!isExpectedCause(sqlException)) { logger.info("quit doPushDownQuery because prior exception thrown is unexpected"); return null; String completed = sql; try { completed = schemaCompletion(sql, defaultSchema); } catch (SqlParseException e) {
@Test public void testSchemaCompletionWithComplexSubquery() throws SqlParseException { String sql = "SELECT a, b " + "FROM (" + " SELECT c, d, sum(p) " + " FROM table1 t1, DB.table2 t2 " + " WHERE t1.c > t2.d " + " GROUP BY t.e" + " HAVING sum(p) > 100" + " ORDER BY t2.f" + ") at1 " + "INNER JOIN table3 t3 " + "ON at1.c = t3.c " + "WHERE t3.d > 0 " + "ORDER BY t3.e"; String exceptSQL = "SELECT a, b " + "FROM (" + " SELECT c, d, sum(p) " + " FROM EDW.table1 t1, DB.table2 t2 " + " WHERE t1.c > t2.d " + " GROUP BY t.e" + " HAVING sum(p) > 100" + " ORDER BY t2.f" + ") at1 " + "INNER JOIN EDW.table3 t3 " + "ON at1.c = t3.c " + "WHERE t3.d > 0 " + "ORDER BY t3.e"; Assert.assertEquals(exceptSQL, PushDownUtil.schemaCompletion(sql, "EDW")); }
public SQLResponse update(SQLRequest sqlRequest) throws Exception { // non select operations, only supported when enable pushdown logger.debug("Query pushdown enabled, redirect the non-select query to pushdown engine."); Connection conn = null; try { conn = QueryConnection.getConnection(sqlRequest.getProject()); Pair<List<List<String>>, List<SelectedColumnMeta>> r = PushDownUtil.tryPushDownNonSelectQuery( sqlRequest.getProject(), sqlRequest.getSql(), conn.getSchema(), BackdoorToggles.getPrepareOnly()); List<SelectedColumnMeta> columnMetas = Lists.newArrayList(); columnMetas.add(new SelectedColumnMeta(false, false, false, false, 1, false, Integer.MAX_VALUE, "c0", "c0", null, null, null, Integer.MAX_VALUE, 128, 1, "char", false, false, false)); return buildSqlResponse(sqlRequest.getProject(), true, r.getFirst(), columnMetas); } catch (Exception e) { logger.info("pushdown engine failed to finish current non-select query"); throw e; } finally { close(null, null, conn); } }
if (!isExpectedCause(sqlException)) { logger.info("quit doPushDownQuery because prior exception thrown is unexpected"); return null; String completed = sql; try { completed = schemaCompletion(sql, defaultSchema); } catch (SqlParseException e) {
@Test public void testSchemaCompletionWithJoin() throws SqlParseException { String sql = "select * from t1 join (select * from t2 join (select * from t3))"; String exceptSQL = "select * from EDW.t1 join (select * from EDW.t2 join (select * from EDW.t3))"; Assert.assertEquals(exceptSQL, PushDownUtil.schemaCompletion(sql, "EDW")); }
+ " ON test_kylin_fact.lstg_site_id = test_sites.site_id\n" + " group by test_cal_dt.week_beg_dt\n" + ") t2\n" + "on t1.week_beg_dt=t2.week_beg_dt limit 5"; Assert.assertEquals(exceptSQL1, PushDownUtil.schemaCompletion(sql1, "EDW")); Assert.assertEquals(exceptSQL2, PushDownUtil.schemaCompletion(sql2, "EDW")); Assert.assertEquals(exceptSQL3, PushDownUtil.schemaCompletion(sql3, "EDW"));
public static Pair<List<List<String>>, List<SelectedColumnMeta>> tryPushDownNonSelectQuery(String project, String sql, String defaultSchema, boolean isPrepare) throws Exception { return tryPushDownQuery(project, sql, defaultSchema, null, false, isPrepare); }
")\n" + // "ORDER BY c_customer_id limit 5"; // Assert.assertEquals(expected, PushDownUtil.schemaCompletion(ori, "EDW"));
public static Pair<List<List<String>>, List<SelectedColumnMeta>> tryPushDownNonSelectQuery(String project, String sql, String defaultSchema, boolean isPrepare) throws Exception { return tryPushDownQuery(project, sql, defaultSchema, null, false, isPrepare); }
public static Pair<List<List<String>>, List<SelectedColumnMeta>> tryPushDownSelectQuery(String project, String sql, String defaultSchema, SQLException sqlException, boolean isPrepare) throws Exception { return tryPushDownQuery(project, sql, defaultSchema, sqlException, true, isPrepare); }