@Test public void debug() throws Exception { String sql = "create table t1( a int,b string, c int) with ( 'connector' = 'collection','data'='[]');" + "create table t2(a int comment '测试',b string,c int) with ( 'connector' = 'print');" + "create view temp_view as select * from t1;" + "insert into t2(a,b,c) select a,b,c from temp_view t1;" + "insert into t2(a,b,c) select a,b,c from temp_view t1;"; List<String> sourceData = Stream.of( new JSONObject().fluentPut("a", 1).fluentPut("b", "1000").fluentPut("c", 2).toJSONString(), new JSONObject().fluentPut("a", 2).fluentPut("b", "1000").fluentPut("c", 3).toJSONString(), new JSONObject().fluentPut("a", 3).fluentPut("b", "2000").fluentPut("c", 4).toJSONString(), new JSONObject().fluentPut("a", 4).fluentPut("b", "2000").fluentPut("c", 5).toJSONString(), new JSONObject().fluentPut("a", 5).fluentPut("b", "3000").fluentPut("c", 6).toJSONString() ).collect(Collectors.toList()); SqlDebugConfig sqlDebugConfig = new SqlDebugConfig(); HashMap<String, SqlDebugConfig.SourceConfig> sourceConfigMap = new HashMap<>(); sourceConfigMap.put("t1", new SqlDebugConfig.SourceConfig(sourceData)); sqlDebugConfig.setSourceConfigMap(sourceConfigMap); sqlDebugConfig.setSql(sql); log.info("sqlDebugConfig={}", JSON.toJSONString(sqlDebugConfig)); Map<String, List<String>> debugResult = SqlDebugDriver.debug(sqlDebugConfig); assert MapUtils.isNotEmpty(debugResult); }
public static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig) throws Exception { Preconditions.checkNotNull(sqlDebugConfig, "sqlDebugConfig should be not null"); Preconditions.checkNotNull(sqlDebugConfig.getSql(), "sql should be not null"); String identifier = UUID.randomUUID().toString(); String debugSql = handleDebugSql(identifier, sqlDebugConfig.getSql(), sqlDebugConfig); log.debug("start sql debug,sql:{}", debugSql); SqlConfig config = SqlConfig.builder().sql(debugSql).jobName("sql_job_debug_test").build(); SqlJob sqlJob = new SqlJob(config); try { CollectionDataWarehouse.registerLock(identifier); sqlJob.start(); return CollectionDataWarehouse.getData(identifier); } finally { CollectionDataWarehouse.remove(identifier); } }
SqlDebugDriver { public static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig) throws Exception { Preconditions.checkNotNull(sqlDebugConfig, "sqlDebugConfig should be not null"); Preconditions.checkNotNull(sqlDebugConfig.getSql(), "sql should be not null"); String identifier = UUID.randomUUID().toString(); String debugSql = handleDebugSql(identifier, sqlDebugConfig.getSql(), sqlDebugConfig); log.debug("start sql debug,sql:{}", debugSql); SqlConfig config = SqlConfig.builder().sql(debugSql).jobName("sql_job_debug_test").build(); SqlJob sqlJob = new SqlJob(config); try { CollectionDataWarehouse.registerLock(identifier); sqlJob.start(); return CollectionDataWarehouse.getData(identifier); } finally { CollectionDataWarehouse.remove(identifier); } } }
SqlDebugDriver { public static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig) throws Exception { Preconditions.checkNotNull(sqlDebugConfig, "sqlDebugConfig should be not null"); Preconditions.checkNotNull(sqlDebugConfig.getSql(), "sql should be not null"); String identifier = UUID.randomUUID().toString(); String debugSql = handleDebugSql(identifier, sqlDebugConfig.getSql(), sqlDebugConfig); log.debug("start sql debug,sql:{}", debugSql); SqlConfig config = SqlConfig.builder().sql(debugSql).jobName("sql_job_debug_test").build(); SqlJob sqlJob = new SqlJob(config); try { CollectionDataWarehouse.registerLock(identifier); sqlJob.start(); return CollectionDataWarehouse.getData(identifier); } finally { CollectionDataWarehouse.remove(identifier); } }  }
SqlDebugDriver { public static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig) throws Exception { Preconditions.checkNotNull(sqlDebugConfig, "sqlDebugConfig should be not null"); Preconditions.checkNotNull(sqlDebugConfig.getSql(), "sql should be not null"); String identifier = UUID.randomUUID().toString(); String debugSql = handleDebugSql(identifier, sqlDebugConfig.getSql(), sqlDebugConfig); log.debug("start sql debug,sql:{}", debugSql); SqlConfig config = SqlConfig.builder().sql(debugSql).jobName("sql_job_debug_test").build(); SqlJob sqlJob = new SqlJob(config); try { CollectionDataWarehouse.registerLock(identifier); sqlJob.start(); return CollectionDataWarehouse.getData(identifier); } finally { CollectionDataWarehouse.remove(identifier); } }  static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig); }
SqlDebugDriver { public static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig) throws Exception { Preconditions.checkNotNull(sqlDebugConfig, "sqlDebugConfig should be not null"); Preconditions.checkNotNull(sqlDebugConfig.getSql(), "sql should be not null"); String identifier = UUID.randomUUID().toString(); String debugSql = handleDebugSql(identifier, sqlDebugConfig.getSql(), sqlDebugConfig); log.debug("start sql debug,sql:{}", debugSql); SqlConfig config = SqlConfig.builder().sql(debugSql).jobName("sql_job_debug_test").build(); SqlJob sqlJob = new SqlJob(config); try { CollectionDataWarehouse.registerLock(identifier); sqlJob.start(); return CollectionDataWarehouse.getData(identifier); } finally { CollectionDataWarehouse.remove(identifier); } }  static Map<String, List<String>> debug(SqlDebugConfig sqlDebugConfig);  }