public ShowSchemasHandler(Planner planner, QueryContext context) { super(planner, context); }
/** Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.SCHEMATA ... */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException{
SqlShowSchemas node = unwrap(sqlNode, SqlShowSchemas.class);
List<SqlNode> selectList = ImmutableList.of((SqlNode) new SqlIdentifier("SCHEMA_NAME", SqlParserPos.ZERO));
SqlNode fromClause = new SqlIdentifier(
ImmutableList.of("INFORMATION_SCHEMA", "SCHEMATA"), null, SqlParserPos.ZERO, null);
SqlNode where = null;
final SqlNode likePattern = node.getLikePattern();
if (likePattern != null) {
where = DrillParserUtil.createCondition(new SqlIdentifier("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);
}