use of org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class ShowFilesHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException {
SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
SchemaPlus drillSchema = defaultSchema;
SqlShowFiles showFiles = unwrap(sqlNode, SqlShowFiles.class);
SqlIdentifier from = showFiles.getDb();
String fromDir = null;
// Show files can be used without from clause, in which case we display the files in the default schema
if (from != null) {
// We are not sure if the full from clause is just the schema or includes table name,
// first try to see if the full path specified is a schema
drillSchema = SchemaUtilites.findSchema(defaultSchema, from.names);
if (drillSchema == null) {
// Entire from clause is not a schema, try to obtain the schema without the last part of the specified clause.
drillSchema = SchemaUtilites.findSchema(defaultSchema, from.names.subList(0, from.names.size() - 1));
// Listing for specific directory: show files in dfs.tmp.specific_directory
fromDir = from.names.get((from.names.size() - 1));
}
if (drillSchema == null) {
throw UserException.validationError().message("Invalid FROM/IN clause [%s]", from.toString()).build(logger);
}
}
WorkspaceSchema wsSchema;
try {
wsSchema = (WorkspaceSchema) drillSchema.unwrap(AbstractSchema.class).getDefaultSchema();
} catch (ClassCastException e) {
throw UserException.validationError().message("SHOW FILES is supported in workspace type schema only. Schema [%s] is not a workspace schema.", SchemaUtilites.getSchemaPath(drillSchema)).build(logger);
}
Path endPath = fromDir == null ? new Path(wsSchema.getDefaultLocation()) : new Path(wsSchema.getDefaultLocation(), fromDir);
// add URI to the path to ensure that directory objects are skipped (see S3AFileSystem.listStatus method)
Path path = new Path(wsSchema.getFS().getUri().toString(), endPath);
List<ShowFilesCommandResult> records = FileSystemUtil.listAllSafe(wsSchema.getFS(), path, false).stream().map(fileStatus -> new ShowFilesCommandResult(new Records.File(wsSchema.getFullSchemaName(), wsSchema, fileStatus))).collect(Collectors.toList());
return DirectPlan.createDirectPlan(context.getCurrentEndpoint(), records, ShowFilesCommandResult.class);
}
use of org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class AnalyzeTableHandler method getColumnList.
/* Generates the column list specified in the ANALYZE statement */
private SqlNodeList getColumnList(final SqlAnalyzeTable sqlAnalyzeTable) {
SqlNodeList columnList = sqlAnalyzeTable.getFieldList();
if (columnList == null || columnList.size() <= 0) {
columnList = new SqlNodeList(SqlParserPos.ZERO);
columnList.add(new SqlIdentifier(SchemaPath.STAR_COLUMN.rootName(), SqlParserPos.ZERO));
}
/*final SqlNodeList columnList = new SqlNodeList(SqlParserPos.ZERO);
final List<String> fields = sqlAnalyzeTable.getFieldNames();
if (fields == null || fields.size() <= 0) {
columnList.add(new SqlIdentifier(SchemaPath.STAR_COLUMN.rootName(), SqlParserPos.ZERO));
} else {
for(String field : fields) {
columnList.add(new SqlIdentifier(field, SqlParserPos.ZERO));
}
}*/
return columnList;
}
use of org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class DrillCompoundIdentifier method getAsSqlNode.
public SqlNode getAsSqlNode(boolean allowNoTableRefCompoundIdentifier) {
if (ids.size() == 1) {
return new SqlIdentifier(Collections.singletonList(ids.get(0).value), ids.get(0).parserPos);
}
int startIndex;
SqlNode node;
if (ids.get(1).isArray()) {
// handle everything post zero index as item operator.
startIndex = 1;
node = new SqlIdentifier(ImmutableList.of(ids.get(0).value), null, ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos));
} else {
if (allowNoTableRefCompoundIdentifier) {
// For certain statements e.g. ANALYZE which only reference one table, compound column names may be referenced
// without the table reference. For such cases, handle everything post one index as item operator.
startIndex = 1;
node = new SqlIdentifier(// Replaces star by empty string. See SqlIdentifier#isStar()
ImmutableList.of(STAR_TO_EMPTY.apply(ids.get(0).value)), null, ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos));
} else {
// handle everything post two index as item operator.
startIndex = 2;
node = new SqlIdentifier(// Replaces star by empty string. See SqlIdentifier#isStar()
ImmutableList.of(ids.get(0).value, STAR_TO_EMPTY.apply(ids.get(1).value)), null, ids.get(0).parserPos, ImmutableList.of(ids.get(0).parserPos, ids.get(1).parserPos));
}
}
for (int i = startIndex; i < ids.size(); i++) {
node = ids.get(i).getNode(node);
}
return node;
}
use of org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class DrillSqlResetOption method getOperandList.
@Override
public List<SqlNode> getOperandList() {
List<SqlNode> operandList = new ArrayList<>();
SqlIdentifier scopeIdentifier = (this.getScope() == null) ? null : new SqlIdentifier(this.getScope(), SqlParserPos.ZERO);
operandList.add(scopeIdentifier);
operandList.add(this.getName());
return ImmutableNullableList.copyOf(operandList);
}
use of org.apache.calcite.sql.SqlIdentifier in project drill by apache.
the class UnsupportedOperatorsVisitor method detectMultiplePartitions.
/**
* Disable multiple partitions in a SELECT-CLAUSE
* If multiple partitions are defined in the query,
* SqlUnsupportedException would be thrown to inform
* @param sqlSelect SELECT-CLAUSE in the query
*/
private void detectMultiplePartitions(SqlSelect sqlSelect) {
for (SqlNode nodeInSelectList : sqlSelect.getSelectList()) {
// enter the first operand of AS operator
if (nodeInSelectList.getKind() == SqlKind.AS && (((SqlCall) nodeInSelectList).getOperandList().get(0).getKind() == SqlKind.OVER)) {
nodeInSelectList = ((SqlCall) nodeInSelectList).getOperandList().get(0);
}
if (nodeInSelectList.getKind() != SqlKind.OVER) {
continue;
}
// This is used to keep track of the window function which has been defined
SqlNode definedWindow = null;
SqlNode window = ((SqlCall) nodeInSelectList).operand(1);
// which is defined in the window list
if (window instanceof SqlIdentifier) {
// Expand the SqlIdentifier as the expression defined in the window list
for (SqlNode sqlNode : sqlSelect.getWindowList()) {
if (((SqlWindow) sqlNode).getDeclName().equalsDeep(window, Litmus.IGNORE)) {
window = sqlNode;
break;
}
}
assert !(window instanceof SqlIdentifier) : "Identifier should have been expanded as a window defined in the window list";
}
// In a SELECT-SCOPE, only a partition can be defined
if (definedWindow == null) {
definedWindow = window;
} else {
if (!definedWindow.equalsDeep(window, Litmus.IGNORE)) {
unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION, "Multiple window definitions in a single SELECT list is not currently supported \n" + "See Apache Drill JIRA: DRILL-3196");
throw new UnsupportedOperationException();
}
}
}
}
Aggregations