use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class LuceneQueryBuilderTest method testWhereRefEqNullWithDifferentTypes.
@Test
public void testWhereRefEqNullWithDifferentTypes() throws Exception {
for (DataType type : DataTypes.PRIMITIVE_TYPES) {
DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(null, "test_primitive"), null).add("x", type).build();
TableRelation tableRelation = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.of(new QualifiedName(tableInfo.ident().name()), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation, new Object[] { null }, SessionContext.SYSTEM_SESSION);
Query query = convert(new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("x = ?"))));
// must always become a MatchNoDocsQuery (empty BooleanQuery)
// string: term query with null would cause NPE
// int/numeric: rangeQuery from null to null would match all
// bool: term would match false too because of the condition in the eq query builder
assertThat(query, instanceOf(BooleanQuery.class));
assertThat(((BooleanQuery) query).clauses().size(), is(0));
}
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class SchemasITest method testTableAlias.
@Test
public void testTableAlias() throws Exception {
execute("create table terminator (model string, good boolean, actor object)");
IndicesAliasesRequest request = new IndicesAliasesRequest();
request.addAlias("entsafter", "terminator");
client().admin().indices().aliases(request).actionGet();
ensureYellow();
DocTableInfo terminatorTable = (DocTableInfo) schemas.getTableInfo(new TableIdent(null, "terminator"));
DocTableInfo entsafterTable = (DocTableInfo) schemas.getTableInfo(new TableIdent(null, "entsafter"));
assertNotNull(terminatorTable);
assertFalse(terminatorTable.isAlias());
assertNotNull(entsafterTable);
assertTrue(entsafterTable.isAlias());
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class SchemasITest method testAliasPartitions.
@Test
public void testAliasPartitions() throws Exception {
execute("create table terminator (model string, good boolean, actor object)");
execute("create table transformer (model string, good boolean, actor object)");
IndicesAliasesRequest request = new IndicesAliasesRequest();
request.addAlias("entsafter", "terminator");
request.addAlias("entsafter", "transformer");
client().admin().indices().aliases(request).actionGet();
ensureYellow();
DocTableInfo entsafterTable = (DocTableInfo) schemas.getTableInfo(new TableIdent(null, "entsafter"));
assertNotNull(entsafterTable);
assertThat(entsafterTable.concreteIndices().length, is(2));
assertThat(Arrays.asList(entsafterTable.concreteIndices()), containsInAnyOrder("terminator", "transformer"));
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class SelectStatementAnalyzerTest method init.
@Before
public void init() throws Exception {
DocTableInfo fooUserTableInfo = TestingTableInfo.builder(new TableIdent("foo", "users"), SHARD_ROUTING).add("id", DataTypes.LONG, null).add("name", DataTypes.STRING, null).addPrimaryKey("id").build();
DocTableInfoFactory fooTableFactory = new TestingDocTableInfoFactory(ImmutableMap.of(fooUserTableInfo.ident(), fooUserTableInfo));
ClusterService clusterService = new NoopClusterService();
sqlExecutor = SQLExecutor.builder(clusterService).enableDefaultTables().addSchema(new DocSchemaInfo("foo", clusterService, fooTableFactory)).build();
}
use of io.crate.metadata.doc.DocTableInfo in project crate by crate.
the class MetaDataToASTNodeResolverTest method testBuildCreateTableColumns.
@Test
public void testBuildCreateTableColumns() throws Exception {
TableIdent ident = new TableIdent("doc", "test");
List<Reference> columns = ImmutableList.of(newReference(ident, "bools", DataTypes.BOOLEAN), newReference(ident, "bytes", DataTypes.BYTE), newReference(ident, "strings", DataTypes.STRING), newReference(ident, "shorts", DataTypes.SHORT), newReference(ident, "floats", DataTypes.FLOAT), newReference(ident, "doubles", DataTypes.DOUBLE), newReference(ident, "ints", DataTypes.INTEGER), newReference(ident, "longs", DataTypes.LONG), newReference(ident, "timestamp", DataTypes.TIMESTAMP), newReference(ident, "ip_addr", DataTypes.IP), newReference(ident, "arr_simple", new ArrayType(DataTypes.STRING)), newReference(ident, "arr_geo_point", new ArrayType(DataTypes.GEO_POINT)), newReference(ident, "arr_obj", new ArrayType(DataTypes.OBJECT), null, ColumnPolicy.STRICT, false), newReference(ident, "arr_obj", DataTypes.LONG, Arrays.asList("col_1"), null, false), newReference(ident, "arr_obj", DataTypes.STRING, Arrays.asList("col_2"), null, false), newReference(ident, "obj", DataTypes.OBJECT, null, ColumnPolicy.DYNAMIC, false), newReference(ident, "obj", DataTypes.LONG, Arrays.asList("col_1"), null, false), newReference(ident, "obj", DataTypes.STRING, Arrays.asList("col_2"), null, false));
DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), null, ImmutableMap.<String, Object>of(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.DYNAMIC);
CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
assertEquals("CREATE TABLE IF NOT EXISTS \"doc\".\"test\" (\n" + " \"bools\" BOOLEAN,\n" + " \"bytes\" BYTE,\n" + " \"strings\" STRING,\n" + " \"shorts\" SHORT,\n" + " \"floats\" FLOAT,\n" + " \"doubles\" DOUBLE,\n" + " \"ints\" INTEGER,\n" + " \"longs\" LONG,\n" + " \"timestamp\" TIMESTAMP,\n" + " \"ip_addr\" IP,\n" + " \"arr_simple\" ARRAY(STRING),\n" + " \"arr_geo_point\" ARRAY(GEO_POINT),\n" + " \"arr_obj\" ARRAY(OBJECT (STRICT) AS (\n" + " \"col_1\" LONG,\n" + " \"col_2\" STRING\n" + " )),\n" + " \"obj\" OBJECT (DYNAMIC) AS (\n" + " \"col_1\" LONG,\n" + " \"col_2\" STRING\n" + " )\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + " column_policy = 'dynamic',\n" + " number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Aggregations