DRILL-601: Support for 'Show files' command
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/fe2986dc Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/fe2986dc Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/fe2986dc Branch: refs/heads/master Commit: fe2986dceb4558e7ee6f2b55ebf4ad59815d880d Parents: 88e3153 Author: Mehant Baid <[email protected]> Authored: Fri May 9 00:56:41 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Fri May 9 17:19:55 2014 -0700 ---------------------------------------------------------------------- exec/java-exec/src/main/codegen/data/Parser.tdd | 6 +- .../src/main/codegen/includes/parserImpls.ftl | 19 ++++ .../planner/sql/handlers/ShowFileHandler.java | 96 ++++++++++++++++++++ .../sql/handlers/ShowFilesCommandResult.java | 85 +++++++++++++++++ .../exec/planner/sql/parser/SqlShowFiles.java | 71 +++++++++++++++ .../exec/store/dfs/FileSystemSchemaFactory.java | 11 ++- .../exec/store/dfs/HasFileSystemSchema.java | 26 ++++++ .../exec/store/dfs/WorkspaceSchemaFactory.java | 8 +- .../drill/exec/store/pojo/PojoDataType.java | 3 + .../drill/exec/store/pojo/PojoRecordReader.java | 4 + .../apache/drill/exec/store/pojo/Writers.java | 19 ++++ .../apache/drill/jdbc/test/TestJdbcQuery.java | 37 +++++++- 12 files changed, 378 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/codegen/data/Parser.tdd ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/data/Parser.tdd b/exec/java-exec/src/main/codegen/data/Parser.tdd index 176ee79..8850542 100644 --- a/exec/java-exec/src/main/codegen/data/Parser.tdd +++ b/exec/java-exec/src/main/codegen/data/Parser.tdd @@ -33,7 +33,8 @@ "SCHEMAS", "SHOW", "TABLES", - "USE" + "USE", + "FILES" ] # List of methods for parsing custom SQL statements. @@ -43,7 +44,8 @@ "SqlDescribeTable()", "SqlUseSchema()", "SqlCreateOrReplaceView()", - "SqlDropView()" + "SqlDropView()", + "SqlShowFiles()" ] # List of methods for parsing custom literals. http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/codegen/includes/parserImpls.ftl ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/includes/parserImpls.ftl b/exec/java-exec/src/main/codegen/includes/parserImpls.ftl index 5b6e2b5..71afdc3 100644 --- a/exec/java-exec/src/main/codegen/includes/parserImpls.ftl +++ b/exec/java-exec/src/main/codegen/includes/parserImpls.ftl @@ -54,6 +54,25 @@ SqlNode SqlShowTables() : } /** + * Parses statement + * SHOW FILES [{FROM | IN} schema] + */ +SqlNode SqlShowFiles() : +{ + SqlParserPos pos = null; + SqlIdentifier db = null; +} +{ + <SHOW> { pos = getPos(); } + <FILES> + (<FROM> | <IN>) { db = CompoundIdentifier(); } + { + return new SqlShowFiles(pos, db); + } +} + + +/** * Parses statement SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr] */ SqlNode SqlShowSchemas() : http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java new file mode 100644 index 0000000..4f7c424 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFileHandler.java @@ -0,0 +1,96 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.planner.sql.handlers; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import net.hydromatic.optiq.SchemaPlus; +import net.hydromatic.optiq.tools.Planner; +import net.hydromatic.optiq.tools.RelConversionException; +import net.hydromatic.optiq.tools.ValidationException; + +import org.eigenbase.sql.SqlIdentifier; +import org.eigenbase.sql.SqlNode; + +import org.apache.drill.exec.ops.QueryContext; +import org.apache.drill.exec.physical.PhysicalPlan; +import org.apache.drill.exec.planner.sql.DirectPlan; +import org.apache.drill.exec.planner.sql.parser.SqlShowFiles; +import org.apache.drill.exec.store.dfs.HasFileSystemSchema; +import org.apache.drill.exec.store.dfs.shim.DrillFileSystem; + +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.FileStatus; + +public class ShowFileHandler extends DefaultSqlHandler { + static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SetOptionHandler.class); + + public ShowFileHandler(Planner planner, QueryContext context) { + super(planner, context); + } + + @Override + public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException { + + SqlIdentifier from = ((SqlShowFiles) sqlNode).getDb(); + String fromDir = from.names.get((from.names.size() - 1)); + + // Get the correct subschema + SchemaPlus schema = context.getNewDefaultSchema().getParentSchema(); + for (int i = 0; i < from.names.size() - 1 && schema != null; i++) { + schema = schema.getSubSchema(from.names.get(i)); + } + + // Traverse from the root schema if current schema is null + if (schema == null) { + schema = context.getRootSchema(); + + for (int i = 0; i < from.names.size() - 1 && schema != null; i++) { + schema = schema.getSubSchema(from.names.get(i)); + } + + if (schema == null) { + throw new ValidationException("Invalid schema"); + } + } + + DrillFileSystem fs; + + // Get the DrillFileSystem object + try { + HasFileSystemSchema fsSchema = schema.unwrap(HasFileSystemSchema.class); + fs = fsSchema.getFS(); + } catch (ClassCastException e) { + throw new ValidationException("Schema not an instance of file system schema"); + } + + List<ShowFilesCommandResult> rows = new ArrayList<>(); + + for (FileStatus fileStatus : fs.list(false, new Path(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); + } +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFilesCommandResult.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFilesCommandResult.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFilesCommandResult.java new file mode 100644 index 0000000..bcd3055 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ShowFilesCommandResult.java @@ -0,0 +1,85 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.drill.exec.planner.sql.handlers; + +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.MutableDateTime; + +import java.sql.Timestamp; +import java.util.Date; + +public class ShowFilesCommandResult { + + /* Fields that will be returned as columns + * for a 'SHOW FILES' command + */ + + // Name of the file + public String name; + + // Is it a directory + public boolean isDirectory; + + // Is it a file + public boolean isFile; + + // Length of the file + public long length; + + // File owner + public String owner; + + // File group + public String group; + + // File permissions + public String permissions; + + // Access Time + public Timestamp accessTime; + + // Modification Time + public Timestamp modificationTime; + + public ShowFilesCommandResult(String name, + boolean isDirectory, + boolean isFile, + long length, + String owner, + String group, + String permissions, + long accessTime, + long modificationTime) { + this.name = name; + this.isDirectory = isDirectory; + this.isFile = isFile; + this.length = length; + this.owner = owner; + this.group = group; + this.permissions = permissions; + + // Get the timestamp in UTC because Drill's internal TIMESTAMP stores time in UTC + DateTime at = new DateTime(accessTime).withZoneRetainFields(DateTimeZone.UTC); + this.accessTime = new Timestamp(at.getMillis()); + + DateTime mt = new DateTime(modificationTime).withZoneRetainFields(DateTimeZone.UTC); + this.modificationTime = new Timestamp(mt.getMillis()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowFiles.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowFiles.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowFiles.java new file mode 100644 index 0000000..b7fba06 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowFiles.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.planner.sql.parser; + +import com.google.common.collect.Lists; +import net.hydromatic.optiq.tools.Planner; +import org.apache.drill.exec.ops.QueryContext; +import org.apache.drill.exec.planner.sql.handlers.ShowFileHandler; +import org.apache.drill.exec.planner.sql.handlers.ShowTablesHandler; +import org.apache.drill.exec.planner.sql.handlers.SqlHandler; +import org.eigenbase.sql.*; +import org.eigenbase.sql.parser.SqlParserPos; + +import java.util.List; + +/** + * Sql parse tree node to represent statement: + * SHOW FILES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr] + */ +public class SqlShowFiles extends DrillSqlCall { + + private final SqlIdentifier db; + + public static final SqlSpecialOperator OPERATOR = + new SqlSpecialOperator("SHOW_FILES", SqlKind.OTHER); + + public SqlShowFiles(SqlParserPos pos, SqlIdentifier db) { + super(pos); + this.db = db; + } + + @Override + public SqlOperator getOperator() { + return OPERATOR; + } + + @Override + public List<SqlNode> getOperandList() { + List<SqlNode> opList = Lists.newArrayList(); + if (db != null) opList.add(db); + return opList; + } + + @Override + public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { + writer.keyword("SHOW"); + writer.keyword("FILES"); + if (db != null) db.unparse(writer, leftPrec, rightPrec); + } + + @Override + public SqlHandler getSqlHandler(Planner planner, QueryContext context) { + return new ShowFileHandler(planner, context); + } + public SqlIdentifier getDb() { return db; } +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java index 92a1efc..fa60622 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java @@ -36,6 +36,7 @@ import org.apache.drill.exec.store.SchemaFactory; import org.apache.drill.exec.store.dfs.WorkspaceSchemaFactory.WorkspaceSchema; import com.google.common.collect.Maps; +import org.apache.drill.exec.store.dfs.shim.DrillFileSystem; /** @@ -46,6 +47,7 @@ public class FileSystemSchemaFactory implements SchemaFactory{ private List<WorkspaceSchemaFactory> factories; private String schemaName; + private final String defaultSchemaName = "default"; public FileSystemSchemaFactory(String schemaName, List<WorkspaceSchemaFactory> factories) { @@ -61,7 +63,7 @@ public class FileSystemSchemaFactory implements SchemaFactory{ schema.setPlus(plusOfThis); } - public class FileSystemSchema extends AbstractSchema{ + public class FileSystemSchema extends AbstractSchema implements HasFileSystemSchema { private final WorkspaceSchema defaultSchema; private final Map<String, WorkspaceSchema> schemaMap = Maps.newHashMap(); @@ -73,7 +75,7 @@ public class FileSystemSchemaFactory implements SchemaFactory{ schemaMap.put(s.getName(), s); } - defaultSchema = schemaMap.get("default"); + defaultSchema = schemaMap.get(defaultSchemaName); } void setPlus(SchemaPlus plusOfThis){ @@ -116,6 +118,9 @@ public class FileSystemSchemaFactory implements SchemaFactory{ public boolean isMutable() { return defaultSchema.isMutable(); } - } + public DrillFileSystem getFS() { + return defaultSchema.getFS(); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java new file mode 100644 index 0000000..c11887a --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/HasFileSystemSchema.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.store.dfs; + +import net.hydromatic.optiq.SchemaPlus; +import org.apache.drill.exec.store.dfs.shim.DrillFileSystem; + +public interface HasFileSystemSchema { + + public DrillFileSystem getFS(); +} http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java index cbaf651..efd19c5 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java @@ -23,6 +23,7 @@ import java.util.Set; import com.google.common.base.Joiner; import com.google.common.collect.Sets; +import net.hydromatic.optiq.SchemaPlus; import net.hydromatic.optiq.Table; import org.apache.drill.common.exceptions.ExecutionSetupException; import org.apache.drill.exec.planner.logical.DrillTable; @@ -108,7 +109,7 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa public void destroy(DrillTable value) { } - public class WorkspaceSchema extends AbstractSchema { + public class WorkspaceSchema extends AbstractSchema implements HasFileSystemSchema { private ExpandingConcurrentMap<String, DrillTable> tables = new ExpandingConcurrentMap<String, DrillTable>(WorkspaceSchemaFactory.this); private boolean isMutable; @@ -137,6 +138,11 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa public boolean isMutable() { return isMutable; } + + @Override + public DrillFileSystem getFS() { + return fs; + } } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoDataType.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoDataType.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoDataType.java index 8ecb29f..d92ac1c 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoDataType.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoDataType.java @@ -18,6 +18,7 @@ package org.apache.drill.exec.store.pojo; import java.lang.reflect.Field; +import java.sql.Timestamp; import java.util.List; import org.eigenbase.reltype.RelDataType; @@ -53,6 +54,8 @@ public class PojoDataType { types.add(SqlTypeName.VARCHAR); }else if(type.isEnum()){ types.add(SqlTypeName.VARCHAR); + }else if (type == Timestamp.class) { + types.add(SqlTypeName.TIMESTAMP); }else{ throw new RuntimeException(String.format("PojoRecord reader doesn't yet support conversions from type [%s].", type)); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoRecordReader.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoRecordReader.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoRecordReader.java index 4203abc..fc5a9b4 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoRecordReader.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/PojoRecordReader.java @@ -18,6 +18,7 @@ package org.apache.drill.exec.store.pojo; import java.lang.reflect.Field; +import java.sql.Timestamp; import java.util.Iterator; import org.apache.drill.common.exceptions.ExecutionSetupException; @@ -34,6 +35,7 @@ import org.apache.drill.exec.store.pojo.Writers.NBooleanWriter; import org.apache.drill.exec.store.pojo.Writers.NDoubleWriter; import org.apache.drill.exec.store.pojo.Writers.NIntWriter; import org.apache.drill.exec.store.pojo.Writers.StringWriter; +import org.apache.drill.exec.store.pojo.Writers.NTimeStampWriter; public class PojoRecordReader<T> implements RecordReader{ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PojoRecordReader.class); @@ -80,6 +82,8 @@ public class PojoRecordReader<T> implements RecordReader{ writers[i] = new LongWriter(f); }else if(type == String.class){ writers[i] = new StringWriter(f); + }else if (type == Timestamp.class) { + writers[i] = new NTimeStampWriter(f); }else{ throw new ExecutionSetupException(String.format("PojoRecord reader doesn't yet support conversions from type [%s].", type)); } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/Writers.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/Writers.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/Writers.java index b986be8..03732a0 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/Writers.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/pojo/Writers.java @@ -21,6 +21,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import java.lang.reflect.Field; +import java.sql.Timestamp; import org.apache.drill.common.types.TypeProtos.MinorType; import org.apache.drill.common.types.Types; @@ -34,6 +35,7 @@ import org.apache.drill.exec.vector.NullableBitVector; import org.apache.drill.exec.vector.NullableFloat8Vector; import org.apache.drill.exec.vector.NullableIntVector; import org.apache.drill.exec.vector.NullableVarCharVector; +import org.apache.drill.exec.vector.NullableTimeStampVector; import com.google.common.base.Charsets; @@ -239,4 +241,21 @@ public class Writers { } } + + public static class NTimeStampWriter extends AbstractWriter<NullableTimeStampVector>{ + + public NTimeStampWriter(Field field) { + super(field, Types.optional(MinorType.TIMESTAMP)); + if(field.getType() != Timestamp.class) throw new IllegalStateException(); + } + + @Override + public boolean writeField(Object pojo, int outboundIndex) throws IllegalArgumentException, IllegalAccessException { + Timestamp o = (Timestamp) field.get(pojo); + if(o != null){ + return vector.getMutator().setSafe(outboundIndex, o.getTime()); + } + return true; + } + } } http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/fe2986dc/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java ---------------------------------------------------------------------- diff --git a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java index ded0848..a149ad2 100644 --- a/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java +++ b/exec/jdbc/src/test/java/org/apache/drill/jdbc/test/TestJdbcQuery.java @@ -17,6 +17,8 @@ */ package org.apache.drill.jdbc.test; +import java.lang.Exception; +import java.lang.RuntimeException; import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; @@ -744,4 +746,37 @@ public class TestJdbcQuery extends JdbcTest{ } }); } -} + + @Test + public void testShowFiles() throws Exception { + testQuery("show files from dfs.`/tmp`"); + + } + + + @Test + public void testShowFilesWithDefaultSchema() throws Exception{ + JdbcAssert.withNoDefaultSchema().withConnection(new Function<Connection, Void>() { + public Void apply(Connection connection) { + try { + Statement statement = connection.createStatement(); + + // change default schema + statement.executeQuery("USE dfs.`default`"); + + // show files + ResultSet resultSet = statement.executeQuery("show files from `/tmp`"); + + System.out.println(JdbcAssert.toString(resultSet)); + + statement.close(); + return null; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + +} \ No newline at end of file
