Search in sources :

Example 1 with TextTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider in project beam by apache.

the class BeamSqlCliTest method testExecute_createTableWithPrefixArrayField.

@Test
public void testExecute_createTableWithPrefixArrayField() throws Exception {
    InMemoryMetaStore metaStore = new InMemoryMetaStore();
    metaStore.registerProvider(new TextTableProvider());
    BeamSqlCli cli = new BeamSqlCli().metaStore(metaStore);
    cli.execute("CREATE EXTERNAL TABLE person (\n" + "id int COMMENT 'id', \n" + "name varchar COMMENT 'name', \n" + "age int COMMENT 'age', \n" + "tags ARRAY<VARCHAR>, \n" + "matrix ARRAY<ARRAY<INTEGER>> \n" + ") \n" + "TYPE 'text' \n" + "COMMENT '' LOCATION '/home/admin/orders'");
    Table table = metaStore.getTables().get("person");
    assertNotNull(table);
    assertEquals(Stream.of(Field.of("id", INTEGER).withDescription("id").withNullable(true), Field.of("name", VARCHAR).withDescription("name").withNullable(true), Field.of("age", INTEGER).withDescription("age").withNullable(true), Field.of("tags", Schema.FieldType.array(VARCHAR)).withNullable(true), Field.of("matrix", Schema.FieldType.array(Schema.FieldType.array(INTEGER))).withNullable(true)).collect(toSchema()), table.getSchema());
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) TextTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) Test(org.junit.Test)

Example 2 with TextTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider in project beam by apache.

the class BeamSqlCliTest method testExecute_createTableWithPrefixMapField.

@Test
public void testExecute_createTableWithPrefixMapField() throws Exception {
    InMemoryMetaStore metaStore = new InMemoryMetaStore();
    metaStore.registerProvider(new TextTableProvider());
    BeamSqlCli cli = new BeamSqlCli().metaStore(metaStore);
    cli.execute("CREATE EXTERNAL TABLE person (\n" + "id int COMMENT 'id', \n" + "name varchar COMMENT 'name', \n" + "age int COMMENT 'age', \n" + "tags MAP<VARCHAR, VARCHAR>, \n" + "nestedMap MAP<INTEGER, MAP<VARCHAR, INTEGER>> \n" + ") \n" + "TYPE 'text' \n" + "COMMENT '' LOCATION '/home/admin/orders'");
    Table table = metaStore.getTables().get("person");
    assertNotNull(table);
    assertEquals(Stream.of(Field.of("id", INTEGER).withDescription("id").withNullable(true), Field.of("name", VARCHAR).withDescription("name").withNullable(true), Field.of("age", INTEGER).withDescription("age").withNullable(true), Field.of("tags", Schema.FieldType.map(VARCHAR, VARCHAR)).withNullable(true), Field.of("nestedMap", Schema.FieldType.map(INTEGER, Schema.FieldType.map(VARCHAR, INTEGER))).withNullable(true)).collect(toSchema()), table.getSchema());
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) TextTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) Test(org.junit.Test)

Example 3 with TextTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider in project beam by apache.

the class BeamSqlCliTest method testExecute_createTableWithRowField.

@Test
public void testExecute_createTableWithRowField() throws Exception {
    InMemoryMetaStore metaStore = new InMemoryMetaStore();
    metaStore.registerProvider(new TextTableProvider());
    BeamSqlCli cli = new BeamSqlCli().metaStore(metaStore);
    cli.execute("CREATE EXTERNAL TABLE person (\n" + "id int COMMENT 'id', \n" + "name varchar COMMENT 'name', \n" + "age int COMMENT 'age', \n" + "address ROW ( \n" + "  street VARCHAR, \n" + "  country VARCHAR \n" + "  ), \n" + "addressAngular ROW< \n" + "  street VARCHAR, \n" + "  country VARCHAR \n" + "  >, \n" + "isRobot BOOLEAN" + ") \n" + "TYPE 'text' \n" + "COMMENT '' LOCATION '/home/admin/orders'");
    Table table = metaStore.getTables().get("person");
    assertNotNull(table);
    assertEquals(Stream.of(Field.of("id", INTEGER).withDescription("id").withNullable(true), Field.of("name", VARCHAR).withDescription("name").withNullable(true), Field.of("age", INTEGER).withDescription("age").withNullable(true), Field.of("address", Schema.FieldType.row(Schema.builder().addNullableField("street", VARCHAR).addNullableField("country", VARCHAR).build())).withNullable(true), Field.of("addressAngular", Schema.FieldType.row(Schema.builder().addNullableField("street", VARCHAR).addNullableField("country", VARCHAR).build())).withNullable(true), Field.of("isRobot", BOOLEAN).withNullable(true)).collect(toSchema()), table.getSchema());
}
Also used : Table(org.apache.beam.sdk.extensions.sql.meta.Table) TextTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) Test(org.junit.Test)

Example 4 with TextTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider in project beam by apache.

the class BeamSqlCliTest method testExecute_dropTable_assertTableRemovedFromPlanner.

@Test(expected = ParseException.class)
public void testExecute_dropTable_assertTableRemovedFromPlanner() throws Exception {
    InMemoryMetaStore metaStore = new InMemoryMetaStore();
    metaStore.registerProvider(new TextTableProvider());
    BeamSqlCli cli = new BeamSqlCli().metaStore(metaStore);
    cli.execute("CREATE EXTERNAL TABLE person (\n" + "id int COMMENT 'id', \n" + "name varchar COMMENT 'name', \n" + "age int COMMENT 'age') \n" + "TYPE 'text' \n" + "COMMENT '' LOCATION '/home/admin/orders'");
    cli.execute("drop table person");
    cli.explainQuery("select * from person");
}
Also used : TextTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) Test(org.junit.Test)

Example 5 with TextTableProvider

use of org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider in project beam by apache.

the class BeamSqlCliTest method testExplainQuery.

@Test
public void testExplainQuery() throws Exception {
    InMemoryMetaStore metaStore = new InMemoryMetaStore();
    metaStore.registerProvider(new TextTableProvider());
    BeamSqlCli cli = new BeamSqlCli().metaStore(metaStore);
    cli.execute("CREATE EXTERNAL TABLE person (\n" + "id int COMMENT 'id', \n" + "name varchar COMMENT 'name', \n" + "age int COMMENT 'age') \n" + "TYPE 'text' \n" + "COMMENT '' LOCATION '/home/admin/orders'");
    String plan = cli.explainQuery("select * from person");
    assertThat(plan, equalTo("BeamCalcRel(expr#0..2=[{inputs}], proj#0..2=[{exprs}])\n" + "  BeamIOSourceRel(table=[[beam, person]])\n"));
}
Also used : TextTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) Test(org.junit.Test)

Aggregations

TextTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider)10 InMemoryMetaStore (org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore)9 Test (org.junit.Test)7 Table (org.apache.beam.sdk.extensions.sql.meta.Table)5 Before (org.junit.Before)2 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 DataflowPipelineOptions (org.apache.beam.runners.dataflow.options.DataflowPipelineOptions)1 Pipeline (org.apache.beam.sdk.Pipeline)1 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)1 BeamSqlPipelineOptions (org.apache.beam.sdk.extensions.sql.impl.BeamSqlPipelineOptions)1 Row (org.apache.beam.sdk.values.Row)1