use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class DrillValidator method deriveAlias.
@Override
public String deriveAlias(SqlNode node, int ordinal) {
if (node instanceof SqlIdentifier) {
SqlIdentifier sqlIdentifier = (SqlIdentifier) node;
changeNamesIfTableIsTemporary(sqlIdentifier);
replaceAliasWithActualName(sqlIdentifier);
}
return SqlValidatorUtil.getAlias(node, ordinal);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class ClickhouseJdbcImplementor method visit.
@Override
public Result visit(JdbcTableScan scan) {
SqlIdentifier sqlIdentifier = scan.jdbcTable.tableName();
Iterator<String> iter = sqlIdentifier.names.iterator();
Preconditions.checkArgument(sqlIdentifier.names.size() == 3, "size of clickhouse table names:[%s] is not 3", sqlIdentifier.toString());
iter.next();
sqlIdentifier.setNames(ImmutableList.copyOf(iter), null);
return result(sqlIdentifier, ImmutableList.of(Clause.FROM), scan, null);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class MetastoreAnalyzeTableHandler method getColumnList.
/**
* Generates the column list with {@link SchemaPath#DYNAMIC_STAR} and columns required for analyze.
*/
private SqlNodeList getColumnList(List<SchemaPath> projectingColumns) {
SqlNodeList columnList = new SqlNodeList(SqlParserPos.ZERO);
columnList.add(new SqlIdentifier(SchemaPath.DYNAMIC_STAR, SqlParserPos.ZERO));
projectingColumns.stream().map(segmentColumn -> new SqlIdentifier(segmentColumn.getRootSegmentPath(), SqlParserPos.ZERO)).forEach(columnList::add);
return columnList;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class DescribeTableHandler method rewrite.
/**
* Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.COLUMNS ...
*/
@Override
public SqlNode rewrite(SqlNode sqlNode) throws ForemanSetupException {
DrillSqlDescribeTable node = unwrap(sqlNode, DrillSqlDescribeTable.class);
try {
List<SqlNode> selectList = Arrays.asList(new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO), new SqlIdentifier(COLS_COL_DATA_TYPE, SqlParserPos.ZERO), new SqlIdentifier(COLS_COL_IS_NULLABLE, SqlParserPos.ZERO));
SqlNode fromClause = new SqlIdentifier(Arrays.asList(IS_SCHEMA_NAME, InfoSchemaTableType.COLUMNS.name()), SqlParserPos.ZERO);
SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
List<String> schemaPathGivenInCmd = Util.skipLast(node.getTable().names);
SchemaPlus schema = SchemaUtilites.findSchema(defaultSchema, schemaPathGivenInCmd);
if (schema == null) {
SchemaUtilites.throwSchemaNotFoundException(defaultSchema, SchemaUtilites.getSchemaPath(schemaPathGivenInCmd));
}
if (SchemaUtilites.isRootSchema(schema)) {
throw UserException.validationError().message("No schema selected.").build(logger);
}
// find resolved schema path
AbstractSchema drillSchema = SchemaUtilites.unwrapAsDrillSchemaInstance(schema);
String schemaPath = drillSchema.getFullSchemaName();
String tableName = Util.last(node.getTable().names);
if (schema.getTable(tableName) == null) {
throw UserException.validationError().message("Unknown table [%s] in schema [%s]", tableName, schemaPath).build(logger);
}
SqlNode schemaCondition = null;
if (!SchemaUtilites.isRootSchema(schema)) {
schemaCondition = DrillParserUtil.createCondition(new SqlIdentifier(SHRD_COL_TABLE_SCHEMA, SqlParserPos.ZERO), SqlStdOperatorTable.EQUALS, SqlLiteral.createCharString(schemaPath, Util.getDefaultCharset().name(), SqlParserPos.ZERO));
}
SqlNode tableNameColumn = new SqlIdentifier(SHRD_COL_TABLE_NAME, SqlParserPos.ZERO);
// if table names are case insensitive, wrap column values and condition in lower function
if (!drillSchema.areTableNamesCaseSensitive()) {
tableNameColumn = SqlStdOperatorTable.LOWER.createCall(SqlParserPos.ZERO, tableNameColumn);
tableName = tableName.toLowerCase();
}
SqlNode where = DrillParserUtil.createCondition(tableNameColumn, SqlStdOperatorTable.EQUALS, SqlLiteral.createCharString(tableName, Util.getDefaultCharset().name(), SqlParserPos.ZERO));
where = DrillParserUtil.createCondition(schemaCondition, SqlStdOperatorTable.AND, where);
SqlNode columnFilter = null;
if (node.getColumn() != null) {
columnFilter = DrillParserUtil.createCondition(SqlStdOperatorTable.LOWER.createCall(SqlParserPos.ZERO, new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO)), SqlStdOperatorTable.EQUALS, SqlLiteral.createCharString(node.getColumn().toString().toLowerCase(), Util.getDefaultCharset().name(), SqlParserPos.ZERO));
} else if (node.getColumnQualifier() != null) {
SqlNode columnQualifier = node.getColumnQualifier();
SqlNode column = new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO);
if (columnQualifier instanceof SqlCharStringLiteral) {
NlsString conditionString = ((SqlCharStringLiteral) columnQualifier).getNlsString();
columnQualifier = SqlCharStringLiteral.createCharString(conditionString.getValue().toLowerCase(), conditionString.getCharsetName(), columnQualifier.getParserPosition());
column = SqlStdOperatorTable.LOWER.createCall(SqlParserPos.ZERO, column);
}
columnFilter = DrillParserUtil.createCondition(column, SqlStdOperatorTable.LIKE, columnQualifier);
}
where = DrillParserUtil.createCondition(where, SqlStdOperatorTable.AND, columnFilter);
return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO), fromClause, where, null, null, null, null, null, null);
} catch (Exception ex) {
throw UserException.planError(ex).message("Error while rewriting DESCRIBE query: %d", ex.getMessage()).build(logger);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class RefreshMetadataHandler method getColumnList.
/**
* Generates the column list specified in the Refresh statement
* @param sqlrefreshMetadata sql parse node representing refresh statement
* @return list of columns specified in the refresh command
*/
private SqlNodeList getColumnList(final SqlRefreshMetadata sqlrefreshMetadata) {
SqlNodeList columnList = sqlrefreshMetadata.getFieldList();
if (SqlNodeList.isEmptyList(columnList)) {
columnList = new SqlNodeList(SqlParserPos.ZERO);
columnList.add(new SqlIdentifier(SchemaPath.STAR_COLUMN.rootName(), SqlParserPos.ZERO));
}
return columnList;
}
Aggregations