@Test public void testConvertColumn() throws SQLException, SqlParseException { DataSourceDefProvider provider = DataSourceDefProvider.getInstance(); ConvMaster master = new ConvMaster(provider.getDefault(), provider.getById(TEST_TARGET)); SqlConverter converter = new SqlConverter(new SqlConverter.IConfigurer() { @Override public boolean skipDefaultConvert() { return false; } @Override public boolean skipHandleDefault() { return false; } @Override public boolean useUppercaseDefault() { return true; } @Override public String fixAfterDefaultConvert(String orig) { return orig; } @Override public SqlDialect getSqlDialect() { return SqlDialect.CALCITE; } @Override public boolean allowNoOffset() { return true; } @Override public boolean allowFetchNoRows() { return true; } @Override public boolean allowNoOrderByWithFetch() { return true; } @Override public String getPagingType() { return "AUTO"; } @Override public boolean isCaseSensitive() { return true; } @Override public boolean enableCache() { return true; } @Override public boolean enableQuote() { return true; } @Override public String fixIdentifierCaseSensitve(String orig) { return orig.toUpperCase(Locale.ROOT); } @Override public String getTransactionIsolationLevel() { return null; } }, master); Assert.assertEquals("\"TEST\".\"AA\"", converter.convertColumn("`test`.`aa`", "`")); Assert.assertEquals("\"TEST\".\"AA\"", converter.convertColumn("`test`.aa", "`")); Assert.assertEquals("\"TEST\".\"AA\"", converter.convertColumn("test.aa", "`")); }
public String convertColumn(String column, String originQuote) { String converted = column.replace(originQuote, ""); try { SqlNode sqlNode = SqlParser.create(converted).parseExpression(); sqlNode = sqlNode.accept(sqlNodeConverter); converted = sqlWriter.format(sqlNode); } catch (Throwable e) { logger.error("Failed to default convert Column, will use the input: {}", column, e); } finally { sqlWriter.reset(); } return converted; }
SqlConverter { public String convertColumn(String column, String originQuote) { String converted = column.replace(originQuote, ""); try { SqlNode sqlNode = SqlParser.create(converted).parseExpression(); sqlNode = sqlNode.accept(sqlNodeConverter); converted = sqlWriter.format(sqlNode); } catch (Throwable e) { logger.error("Failed to default convert Column, will use the input: {}", column, e); } finally { sqlWriter.reset(); } return converted; } }
SqlConverter { public String convertColumn(String column, String originQuote) { String converted = column.replace(originQuote, ""); try { SqlNode sqlNode = SqlParser.create(converted).parseExpression(); sqlNode = sqlNode.accept(sqlNodeConverter); converted = sqlWriter.format(sqlNode); } catch (Throwable e) { logger.error("Failed to default convert Column, will use the input: {}", column, e); } finally { sqlWriter.reset(); } return converted; } SqlConverter(IConfigurer configurer, ConvMaster convMaster); }
SqlConverter { public String convertColumn(String column, String originQuote) { String converted = column.replace(originQuote, ""); try { SqlNode sqlNode = SqlParser.create(converted).parseExpression(); sqlNode = sqlNode.accept(sqlNodeConverter); converted = sqlWriter.format(sqlNode); } catch (Throwable e) { logger.error("Failed to default convert Column, will use the input: {}", column, e); } finally { sqlWriter.reset(); } return converted; } SqlConverter(IConfigurer configurer, ConvMaster convMaster); String convertSql(String orig); String convertColumn(String column, String originQuote); IConfigurer getConfigurer(); }
SqlConverter { public String convertColumn(String column, String originQuote) { String converted = column.replace(originQuote, ""); try { SqlNode sqlNode = SqlParser.create(converted).parseExpression(); sqlNode = sqlNode.accept(sqlNodeConverter); converted = sqlWriter.format(sqlNode); } catch (Throwable e) { logger.error("Failed to default convert Column, will use the input: {}", column, e); } finally { sqlWriter.reset(); } return converted; } SqlConverter(IConfigurer configurer, ConvMaster convMaster); String convertSql(String orig); String convertColumn(String column, String originQuote); IConfigurer getConfigurer();  }