use of org.apache.drill.exec.record.metadata.schema.SchemaContainer in project drill by apache.
the class TestSchemaCommands method testCreateUsingLoad.
@Test
public void testCreateUsingLoad() throws Exception {
File tmpDir = dirTestWatcher.getTmpDir();
File rawSchema = new File(tmpDir, "raw.schema");
File schemaFile = new File(tmpDir, "schema_for_create_using_load.schema");
try {
Files.write(rawSchema.toPath(), Arrays.asList("i int,", "v varchar"));
assertTrue(rawSchema.exists());
testBuilder().sqlQuery("create schema load '%s' path '%s' properties ('k1'='v1', 'k2' = 'v2')", rawSchema.getPath(), schemaFile.getPath()).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Created schema for [%s]", schemaFile.getPath())).go();
SchemaProvider schemaProvider = new PathSchemaProvider(new Path(schemaFile.getPath()));
assertTrue(schemaFile.exists());
SchemaContainer schemaContainer = schemaProvider.read();
assertNull(schemaContainer.getTable());
TupleMetadata schema = schemaContainer.getSchema();
assertNotNull(schema);
assertEquals(2, schema.size());
assertEquals(TypeProtos.MinorType.INT, schema.metadata("i").type());
assertEquals(TypeProtos.MinorType.VARCHAR, schema.metadata("v").type());
assertEquals(2, schema.properties().size());
} finally {
FileUtils.deleteQuietly(rawSchema);
FileUtils.deleteQuietly(schemaFile);
}
}
use of org.apache.drill.exec.record.metadata.schema.SchemaContainer in project drill by apache.
the class TestSchemaCommands method testDescribeJson.
@Test
public void testDescribeJson() throws Exception {
String tableName = "table_describe_json";
String table = String.format("dfs.tmp.%s", tableName);
try {
run("create table %s as select 'a' as c from (values(1))", table);
run("create schema (col int) for table %s", table);
File schemaFile = Paths.get(dirTestWatcher.getDfsTestTmpDir().getPath(), tableName, SchemaProvider.DEFAULT_SCHEMA_NAME).toFile();
SchemaProvider schemaProvider = new PathSchemaProvider(new Path(schemaFile.getPath()));
SchemaContainer schemaContainer = schemaProvider.read();
String schema = PathSchemaProvider.WRITER.writeValueAsString(schemaContainer);
testBuilder().sqlQuery("describe schema for table %s as json", table).unOrdered().baselineColumns("schema").baselineValues(schema).go();
} finally {
run("drop table if exists %s", table);
}
}
use of org.apache.drill.exec.record.metadata.schema.SchemaContainer in project drill by apache.
the class TestSchemaCommands method testSuccessfulCreateForPath.
@Test
public void testSuccessfulCreateForPath() throws Exception {
File tmpDir = dirTestWatcher.getTmpDir();
File schemaFile = new File(tmpDir, "schema_for_successful_create_for_path.schema");
assertFalse(schemaFile.exists());
try {
testBuilder().sqlQuery("create schema (i int not null, v varchar) path '%s'", schemaFile.getPath()).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Created schema for [%s]", schemaFile.getPath())).go();
SchemaProvider schemaProvider = new PathSchemaProvider(new Path(schemaFile.getPath()));
assertTrue(schemaProvider.exists());
SchemaContainer schemaContainer = schemaProvider.read();
assertNull(schemaContainer.getTable());
assertNotNull(schemaContainer.getSchema());
TupleMetadata schema = schemaContainer.getSchema();
ColumnMetadata intColumn = schema.metadata("i");
assertFalse(intColumn.isNullable());
assertEquals(TypeProtos.MinorType.INT, intColumn.type());
ColumnMetadata varcharColumn = schema.metadata("v");
assertTrue(varcharColumn.isNullable());
assertEquals(TypeProtos.MinorType.VARCHAR, varcharColumn.type());
} finally {
FileUtils.deleteQuietly(schemaFile);
}
}
use of org.apache.drill.exec.record.metadata.schema.SchemaContainer in project drill by apache.
the class TestSchemaCommands method testCreateWithoutSchemaProperties.
@Test
public void testCreateWithoutSchemaProperties() throws Exception {
File tmpDir = dirTestWatcher.getTmpDir();
File schemaFile = new File(tmpDir, "schema_for_create_without_properties.schema");
assertFalse(schemaFile.exists());
try {
testBuilder().sqlQuery("create schema (i int not null) path '%s'", schemaFile.getPath()).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Created schema for [%s]", schemaFile.getPath())).go();
SchemaProvider schemaProvider = new PathSchemaProvider(new Path(schemaFile.getPath()));
assertTrue(schemaProvider.exists());
SchemaContainer schemaContainer = schemaProvider.read();
assertNull(schemaContainer.getTable());
TupleMetadata schema = schemaContainer.getSchema();
assertNotNull(schema);
assertNotNull(schema.properties());
assertEquals(0, schema.properties().size());
} finally {
FileUtils.deleteQuietly(schemaFile);
}
}
use of org.apache.drill.exec.record.metadata.schema.SchemaContainer in project drill by apache.
the class TestSchemaCommands method testCreateUsingLoadEmptyFile.
@Test
public void testCreateUsingLoadEmptyFile() throws Exception {
File tmpDir = dirTestWatcher.getTmpDir();
File rawSchema = new File(tmpDir, "raw_empty.schema");
File schemaFile = new File(tmpDir, "schema_for_create_using_load_empty_file.schema");
try {
assertTrue(rawSchema.createNewFile());
testBuilder().sqlQuery("create schema load '%s' path '%s' properties ('k1'='v1', 'k2' = 'v2')", rawSchema.getPath(), schemaFile.getPath()).unOrdered().baselineColumns("ok", "summary").baselineValues(true, String.format("Created schema for [%s]", schemaFile.getPath())).go();
SchemaProvider schemaProvider = new PathSchemaProvider(new Path(schemaFile.getPath()));
assertTrue(schemaFile.exists());
SchemaContainer schemaContainer = schemaProvider.read();
assertNull(schemaContainer.getTable());
TupleMetadata schema = schemaContainer.getSchema();
assertNotNull(schema);
assertEquals(0, schema.size());
assertEquals(2, schema.properties().size());
} finally {
FileUtils.deleteQuietly(rawSchema);
FileUtils.deleteQuietly(schemaFile);
}
}
Aggregations