Search in sources :

Example 36 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class InsertFromValuesAnalyzerTest method init.

@Before
public void init() {
    SQLExecutor.Builder executorBuilder = SQLExecutor.builder(new NoopClusterService()).enableDefaultTables().addDocTable(testAliasTableInfo).addDocTable(nestedClusteredTableInfo);
    TableIdent notNullColumnTableIdent = new TableIdent(null, "not_null_column");
    TestingTableInfo.Builder notNullColumnTable = new TestingTableInfo.Builder(notNullColumnTableIdent, new Routing(ImmutableMap.of())).add("id", DataTypes.INTEGER, null).add("name", DataTypes.STRING, null, ColumnPolicy.DYNAMIC, IndexType.NOT_ANALYZED, false, false);
    executorBuilder.addDocTable(notNullColumnTable);
    TableIdent generatedColumnTableIdent = new TableIdent(null, "generated_column");
    TestingTableInfo.Builder generatedColumnTable = new TestingTableInfo.Builder(generatedColumnTableIdent, new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("ts", DataTypes.TIMESTAMP, null).add("user", DataTypes.OBJECT, null).add("user", DataTypes.STRING, Arrays.asList("name")).addGeneratedColumn("day", DataTypes.TIMESTAMP, "date_trunc('day', ts)", false).addGeneratedColumn("name", DataTypes.STRING, "concat(user['name'], 'bar')", false);
    executorBuilder.addDocTable(generatedColumnTable);
    TableIdent generatedPkColumnTableIdent = new TableIdent(null, "generated_pk_column");
    TestingTableInfo.Builder generatedPkColumnTable = new TestingTableInfo.Builder(generatedPkColumnTableIdent, SHARD_ROUTING).add("serial_no", DataTypes.INTEGER, null).add("product_no", DataTypes.INTEGER, null).add("color", DataTypes.STRING, null).addGeneratedColumn("id", DataTypes.INTEGER, "serial_no + 1", false).addGeneratedColumn("id2", DataTypes.INTEGER, "product_no + 1", false).addPrimaryKey("id").addPrimaryKey("id2");
    executorBuilder.addDocTable(generatedPkColumnTable);
    TableIdent generatedClusteredByTableIdent = new TableIdent(null, "generated_clustered_by_column");
    TestingTableInfo.Builder clusteredByGeneratedTable = new TestingTableInfo.Builder(generatedClusteredByTableIdent, SHARD_ROUTING).add("serial_no", DataTypes.INTEGER, null).add("color", DataTypes.STRING, null).addGeneratedColumn("routing_col", DataTypes.INTEGER, "serial_no + 1", false).clusteredBy("routing_col");
    executorBuilder.addDocTable(clusteredByGeneratedTable);
    TableIdent generatedNestedClusteredByTableIdent = new TableIdent(null, "generated_nested_clustered_by");
    TestingTableInfo.Builder generatedNestedClusteredByInfo = new TestingTableInfo.Builder(generatedNestedClusteredByTableIdent, SHARD_ROUTING).add("o", DataTypes.OBJECT, null, ColumnPolicy.DYNAMIC).add("o", DataTypes.INTEGER, Arrays.asList("serial_number")).addGeneratedColumn("routing_col", DataTypes.INTEGER, "o['serial_number'] + 1", false).clusteredBy("routing_col");
    executorBuilder.addDocTable(generatedNestedClusteredByInfo);
    e = executorBuilder.build();
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) MapBuilder(org.elasticsearch.common.collect.MapBuilder) TableIdent(io.crate.metadata.TableIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) TestingTableInfo(io.crate.metadata.table.TestingTableInfo) Before(org.junit.Before)

Example 37 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class BlobTableAnalyzerTest method init.

@Before
public void init() throws Exception {
    NoopClusterService clusterService = new NoopClusterService();
    TableIdent myBlobsIdent = new TableIdent(BlobSchemaInfo.NAME, "blobs");
    TestingBlobTableInfo myBlobsTableInfo = TableDefinitions.createBlobTable(myBlobsIdent, clusterService);
    e = SQLExecutor.builder(clusterService).addBlobTable(myBlobsTableInfo).build();
}
Also used : TableIdent(io.crate.metadata.TableIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 38 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class CreateAlterTableStatementAnalyzerTest method testCreateTableWithSchemaName.

@Test
public void testCreateTableWithSchemaName() throws Exception {
    CreateTableAnalyzedStatement analysis = e.analyze("create table something.foo (id integer primary key)");
    TableIdent tableIdent = analysis.tableIdent();
    assertThat(tableIdent.schema(), is("something"));
    assertThat(tableIdent.name(), is("foo"));
}
Also used : TableIdent(io.crate.metadata.TableIdent) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 39 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class ColumnPolicyIntegrationTest method testInsertNestedObjectOnCustomSchemaTable.

@Test
public void testInsertNestedObjectOnCustomSchemaTable() throws Exception {
    execute("create table c.dynamic_table (" + "  meta object(strict) as (" + "     meta object" + "  )" + ") with (column_policy='dynamic', number_of_replicas=0)");
    ensureYellow();
    execute("insert into c.dynamic_table (meta) values({meta={a=['a','b']}})");
    execute("refresh table c.dynamic_table");
    execute("insert into c.dynamic_table (meta) values({meta={a=['c','d']}})");
    waitForMappingUpdateOnAll(new TableIdent("c", "dynamic_table"), "meta.meta.a");
    Map<String, Object> sourceMap = getSourceMap("c.dynamic_table");
    assertThat(String.valueOf(nestedValue(sourceMap, "properties.meta.properties.meta.properties.a.type")), is("array"));
    assertThat(String.valueOf(nestedValue(sourceMap, "properties.meta.properties.meta.properties.a.inner.type")), is("string"));
}
Also used : TableIdent(io.crate.metadata.TableIdent) Test(org.junit.Test)

Example 40 with TableIdent

use of io.crate.metadata.TableIdent in project crate by crate.

the class InternalCountOperationTest method testCount.

@Test
public void testCount() throws Exception {
    execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
    execute("refresh table t");
    CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
    assertThat(countOperation.count("t", 0, WhereClause.MATCH_ALL), is(3L));
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new TableIdent(null, "t"));
    TableRelation tableRelation = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(tableInfo.ident().name()), tableRelation);
    SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
    WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'")));
    assertThat(countOperation.count("t", 0, whereClause), is(1L));
}
Also used : QualifiedName(io.crate.sql.tree.QualifiedName) WhereClause(io.crate.analyze.WhereClause) TableInfo(io.crate.metadata.table.TableInfo) TableIdent(io.crate.metadata.TableIdent) Schemas(io.crate.metadata.Schemas) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Aggregations

TableIdent (io.crate.metadata.TableIdent)41 Test (org.junit.Test)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)15 PartitionName (io.crate.metadata.PartitionName)8 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)7 Before (org.junit.Before)7 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 List (java.util.List)5 Routing (io.crate.metadata.Routing)4 QualifiedName (io.crate.sql.tree.QualifiedName)4 BytesRef (org.apache.lucene.util.BytesRef)4 TableRelation (io.crate.analyze.relations.TableRelation)3 ReferenceIdent (io.crate.metadata.ReferenceIdent)3 TestingTableInfo (io.crate.metadata.table.TestingTableInfo)3 SqlExpressions (io.crate.testing.SqlExpressions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)2 ImmutableList (com.google.common.collect.ImmutableList)2 SharedShardContexts (io.crate.action.job.SharedShardContexts)2