Search in sources :

Example 6 with InMemoryMetaStore

use of org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore 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 7 with InMemoryMetaStore

use of org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore 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)

Example 8 with InMemoryMetaStore

use of org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore in project beam by apache.

the class BeamSqlCliTest method testExecute_createTextTable.

@Test
public void testExecute_createTextTable() 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'");
    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)).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 9 with InMemoryMetaStore

use of org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore in project beam by apache.

the class BeamSqlCliTest method testExecute_dropTable.

@Test
public void testExecute_dropTable() 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'");
    Table table = metaStore.getTables().get("person");
    assertNotNull(table);
    cli.execute("drop table person");
    table = metaStore.getTables().get("person");
    assertNull(table);
}
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 10 with InMemoryMetaStore

use of org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore in project beam by apache.

the class BeamSqlExplainTest method setUp.

@Before
public void setUp() throws SqlParseException, RelConversionException, ValidationException {
    metaStore = new InMemoryMetaStore();
    metaStore.registerProvider(new TextTableProvider());
    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 '' ");
    cli.execute("CREATE EXTERNAL TABLE A (\n" + "c1 int COMMENT 'c1',\n" + "c2 int COMMENT 'c2')\n" + "TYPE 'text'\n" + "COMMENT '' ");
    cli.execute("CREATE EXTERNAL TABLE B (\n" + "c1 int COMMENT 'c1',\n" + "c2 int COMMENT 'c2')\n" + "TYPE 'text'\n" + "COMMENT '' ");
}
Also used : TextTableProvider(org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) Before(org.junit.Before)

Aggregations

InMemoryMetaStore (org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore)15 Test (org.junit.Test)12 TextTableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.text.TextTableProvider)9 Table (org.apache.beam.sdk.extensions.sql.meta.Table)8 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)3 Row (org.apache.beam.sdk.values.Row)3 ExecutorService (java.util.concurrent.ExecutorService)2 BeamSqlPipelineOptions (org.apache.beam.sdk.extensions.sql.impl.BeamSqlPipelineOptions)2 TableProvider (org.apache.beam.sdk.extensions.sql.meta.provider.TableProvider)2 JSONObject (com.alibaba.fastjson.JSONObject)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StandardCharsets (java.nio.charset.StandardCharsets)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1