Search in sources :

Example 1 with SqlShowSchemas

use of org.apache.drill.exec.planner.sql.parser.SqlShowSchemas in project drill by axbaretto.

the class ShowSchemasHandler method rewrite.

/**
 * Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.SCHEMATA ...
 */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
    SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class);
    List<SqlNode> selectList = ImmutableList.of((SqlNode) new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO));
    SqlNode fromClause = new SqlIdentifier(ImmutableList.of(IS_SCHEMA_NAME, TAB_SCHEMATA), null, SqlParserPos.ZERO, null);
    SqlNode where = null;
    final SqlNode likePattern = node.getLikePattern();
    if (likePattern != null) {
        where = DrillParserUtil.createCondition(new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO), SqlStdOperatorTable.LIKE, likePattern);
    } else if (node.getWhereClause() != null) {
        where = node.getWhereClause();
    }
    return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO), fromClause, where, null, null, null, null, null, null);
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlShowSchemas(org.apache.drill.exec.planner.sql.parser.SqlShowSchemas) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with SqlShowSchemas

use of org.apache.drill.exec.planner.sql.parser.SqlShowSchemas in project drill by apache.

the class ShowSchemasHandler method rewrite.

/**
 * Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.SCHEMATA ...
 */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws ForemanSetupException {
    SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class);
    List<SqlNode> selectList = Collections.singletonList(new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO));
    SqlNode fromClause = new SqlIdentifier(Arrays.asList(IS_SCHEMA_NAME, InfoSchemaTableType.SCHEMATA.name()), SqlParserPos.ZERO);
    SqlNode where = null;
    SqlNode likePattern = node.getLikePattern();
    if (likePattern != null) {
        SqlNode column = new SqlIdentifier(SCHS_COL_SCHEMA_NAME, SqlParserPos.ZERO);
        // schema names are case insensitive, wrap column in lower function, pattern to lower case
        if (likePattern instanceof SqlCharStringLiteral) {
            NlsString conditionString = ((SqlCharStringLiteral) likePattern).getNlsString();
            likePattern = SqlCharStringLiteral.createCharString(conditionString.getValue().toLowerCase(), conditionString.getCharsetName(), likePattern.getParserPosition());
            column = SqlStdOperatorTable.LOWER.createCall(SqlParserPos.ZERO, column);
        }
        where = DrillParserUtil.createCondition(column, SqlStdOperatorTable.LIKE, likePattern);
    } else if (node.getWhereClause() != null) {
        where = node.getWhereClause();
    }
    return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO), fromClause, where, null, null, null, null, null, null);
}
Also used : SqlSelect(org.apache.calcite.sql.SqlSelect) SqlShowSchemas(org.apache.drill.exec.planner.sql.parser.SqlShowSchemas) NlsString(org.apache.calcite.util.NlsString) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlCharStringLiteral(org.apache.calcite.sql.SqlCharStringLiteral) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)2 SqlNode (org.apache.calcite.sql.SqlNode)2 SqlNodeList (org.apache.calcite.sql.SqlNodeList)2 SqlSelect (org.apache.calcite.sql.SqlSelect)2 SqlShowSchemas (org.apache.drill.exec.planner.sql.parser.SqlShowSchemas)2 SqlCharStringLiteral (org.apache.calcite.sql.SqlCharStringLiteral)1 NlsString (org.apache.calcite.util.NlsString)1