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();
}
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();
}
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"));
}
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"));
}
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));
}
Aggregations