Search in sources :

Example 11 with DocTableInfo

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));
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) TermsQuery(org.apache.lucene.queries.TermsQuery) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) WithinPrefixTreeQuery(org.apache.lucene.spatial.prefix.WithinPrefixTreeQuery) QualifiedName(io.crate.sql.tree.QualifiedName) WhereClause(io.crate.analyze.WhereClause) DataType(io.crate.types.DataType) TableIdent(io.crate.metadata.TableIdent) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 12 with DocTableInfo

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());
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 13 with DocTableInfo

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"));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 14 with DocTableInfo

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();
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) TableIdent(io.crate.metadata.TableIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) DocTableInfoFactory(io.crate.metadata.doc.DocTableInfoFactory) TestingDocTableInfoFactory(io.crate.metadata.doc.TestingDocTableInfoFactory) Before(org.junit.Before)

Example 15 with DocTableInfo

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));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)127 Test (org.junit.Test)56 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)40 Symbol (io.crate.expression.symbol.Symbol)27 Reference (io.crate.metadata.Reference)27 SQLExecutor (io.crate.testing.SQLExecutor)25 RelationName (io.crate.metadata.RelationName)24 DocTableRelation (io.crate.analyze.relations.DocTableRelation)20 ColumnIdent (io.crate.metadata.ColumnIdent)20 TableInfo (io.crate.metadata.table.TableInfo)18 Assignments (io.crate.expression.symbol.Assignments)16 Row (io.crate.data.Row)14 PlannerContext (io.crate.planner.PlannerContext)13 Before (org.junit.Before)13 RowConsumer (io.crate.data.RowConsumer)12 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)12 PartitionName (io.crate.metadata.PartitionName)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12