Search in sources :

Example 6 with SqlParser

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);
}
Also used : SqlParser(org.apache.calcite.sql.parser.SqlParser) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 7 with SqlParser

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);
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlParser(org.apache.calcite.sql.parser.SqlParser) Test(org.junit.Test)

Example 8 with SqlParser

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);
}
Also used : SqlParser(org.apache.calcite.sql.parser.SqlParser) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Example 9 with SqlParser

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;
    }
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlParseException(org.apache.calcite.sql.parser.SqlParseException) SqlParser(org.apache.calcite.sql.parser.SqlParser) SqlOrderBy(org.apache.calcite.sql.SqlOrderBy) SqlNode(org.apache.calcite.sql.SqlNode)

Example 10 with SqlParser

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();
}
Also used : SqlParser(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser) SqlNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode)

Aggregations

SqlParser (org.apache.calcite.sql.parser.SqlParser)9 SqlNode (org.apache.calcite.sql.SqlNode)8 SqlParseException (org.apache.calcite.sql.parser.SqlParseException)4 Test (org.junit.Test)3 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)2 SqlSelect (org.apache.calcite.sql.SqlSelect)2 SqlValidator (org.apache.calcite.sql.validate.SqlValidator)2 ImmutableList (com.google.common.collect.ImmutableList)1 HazelcastSqlParser (com.hazelcast.jet.sql.impl.calcite.parser.HazelcastSqlParser)1 UnsupportedOperationVisitor (com.hazelcast.jet.sql.impl.validate.UnsupportedOperationVisitor)1 QueryParameterMetadata (com.hazelcast.sql.impl.QueryParameterMetadata)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SqlNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlNode)1 SqlParser (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser)1 EnumerableConvention (org.apache.calcite.adapter.enumerable.EnumerableConvention)1 EnumerableRel (org.apache.calcite.adapter.enumerable.EnumerableRel)1 AvaticaParameter (org.apache.calcite.avatica.AvaticaParameter)1 ColumnMetaData (org.apache.calcite.avatica.ColumnMetaData)1 Meta (org.apache.calcite.avatica.Meta)1