use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser in project spf4j by zolyfarkas.
the class AvroQueryTest method testSqlProjection.
@Test
public void testSqlProjection() throws SqlParseException {
SqlParser.Config cfg = SqlParser.configBuilder().setCaseSensitive(true).setIdentifierMaxLength(255).setLex(Lex.JAVA).build();
SqlParser parser = SqlParser.create("select a.b as custom, c, d, e", cfg);
SqlNode expr = parser.parseQuery();
LOG.debug("expression", expr);
Assert.assertNotNull(expr);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser in project spf4j by zolyfarkas.
the class AvroQueryTest method testSqlParser.
@Test
public void testSqlParser() throws SqlParseException {
SqlParser.Config cfg = SqlParser.configBuilder().setCaseSensitive(true).setIdentifierMaxLength(255).setLex(Lex.JAVA).build();
SqlParser parser = SqlParser.create("select a.id, a.name as n1, b.name as n2 from a, b where a.id = b.id", cfg);
SqlSelect select = (SqlSelect) parser.parseQuery();
LOG.debug("Select", select);
Assert.assertNotNull(select);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser in project spf4j by zolyfarkas.
the class AvroQueryTest method testSqlFilter.
@Test
public void testSqlFilter() throws SqlParseException {
SqlParser.Config cfg = SqlParser.configBuilder().setCaseSensitive(true).setIdentifierMaxLength(255).setLex(Lex.JAVA).build();
SqlParser parser = SqlParser.create("a = b and c = d", cfg);
SqlNode expr = parser.parseExpression();
LOG.debug("expression", expr);
Assert.assertNotNull(expr);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser in project incubator-gobblin by apache.
the class JdbcExtractor method hasJoinOperation.
/**
* Check if the SELECT query has join operation
*/
public static boolean hasJoinOperation(String selectQuery) {
if (selectQuery == null || selectQuery.length() == 0) {
return false;
}
SqlParser sqlParser = SqlParser.create(selectQuery);
try {
SqlNode all = sqlParser.parseQuery();
SqlSelect query;
if (all instanceof SqlSelect) {
query = (SqlSelect) all;
} else if (all instanceof SqlOrderBy) {
query = (SqlSelect) ((SqlOrderBy) all).query;
} else {
throw new UnsupportedOperationException("The select query is type of " + all.getClass() + " which is not supported here");
}
return query.getFrom().getKind() == SqlKind.JOIN;
} catch (SqlParseException e) {
return false;
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser in project beam by apache.
the class QueryReader method getQueryIdentifiers.
/**
* Parse query and get all its identifiers.
*
* @param queryString
* @return Set of SQL query identifiers as strings.
* @throws SqlParseException
*/
public static Set<String> getQueryIdentifiers(String queryString) throws SqlParseException {
SqlParser parser = SqlParser.create(queryString);
SqlNode parsedQuery = parser.parseQuery();
SqlTransformRunner.SqlIdentifierVisitor sqlVisitor = new SqlTransformRunner.SqlIdentifierVisitor();
parsedQuery.accept(sqlVisitor);
return sqlVisitor.getIdentifiers();
}
Aggregations