use of org.apache.drill.exec.planner.sql.parser.SqlShowFiles in project drill by axbaretto.
the class ShowFileHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
SqlIdentifier from = ((SqlShowFiles) sqlNode).getDb();
DrillFileSystem fs;
String defaultLocation;
String fromDir = "./";
SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
SchemaPlus drillSchema = defaultSchema;
// 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));
fromDir = 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);
}
// Get the file system object
fs = wsSchema.getFS();
// Get the default path
defaultLocation = wsSchema.getDefaultLocation();
List<ShowFilesCommandResult> rows = new ArrayList<>();
for (FileStatus fileStatus : FileSystemUtil.listAll(fs, new Path(defaultLocation, fromDir), false)) {
ShowFilesCommandResult result = new ShowFilesCommandResult(fileStatus.getPath().getName(), fileStatus.isDirectory(), fileStatus.isFile(), fileStatus.getLen(), fileStatus.getOwner(), fileStatus.getGroup(), fileStatus.getPermission().toString(), fileStatus.getAccessTime(), fileStatus.getModificationTime());
rows.add(result);
}
return DirectPlan.createDirectPlan(context.getCurrentEndpoint(), rows, ShowFilesCommandResult.class);
}
use of org.apache.drill.exec.planner.sql.parser.SqlShowFiles 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.drill.exec.planner.sql.parser.SqlShowFiles in project drill by apache.
the class ShowFileHandler method getPlan.
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
SqlIdentifier from = ((SqlShowFiles) sqlNode).getDb();
DrillFileSystem fs = null;
String defaultLocation = null;
String fromDir = "./";
SchemaPlus defaultSchema = config.getConverter().getDefaultSchema();
SchemaPlus drillSchema = defaultSchema;
// 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));
fromDir = 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);
}
// Get the file system object
fs = wsSchema.getFS();
// Get the default path
defaultLocation = wsSchema.getDefaultLocation();
List<ShowFilesCommandResult> rows = new ArrayList<>();
for (FileStatus fileStatus : fs.list(false, new Path(defaultLocation, fromDir))) {
ShowFilesCommandResult result = new ShowFilesCommandResult(fileStatus.getPath().getName(), fileStatus.isDir(), !fileStatus.isDir(), fileStatus.getLen(), fileStatus.getOwner(), fileStatus.getGroup(), fileStatus.getPermission().toString(), fileStatus.getAccessTime(), fileStatus.getModificationTime());
rows.add(result);
}
return DirectPlan.createDirectPlan(context.getCurrentEndpoint(), rows.iterator(), ShowFilesCommandResult.class);
}
Aggregations