Search in sources :

Example 61 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class DocTableRelationTest method testUpdatingCompoundPrimaryKeyThrowsCorrectException.

@Test
public void testUpdatingCompoundPrimaryKeyThrowsCorrectException() {
    DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "t1"), "create table doc.t1 (i int, j int, primary key (i, j))", clusterService);
    DocTableRelation rel = new DocTableRelation(tableInfo);
    expectedException.expect(ColumnValidationException.class);
    expectedException.expectMessage("Validation failed for i: Updating a primary key is not supported");
    rel.ensureColumnCanBeUpdated(new ColumnIdent("i"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 62 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class SelectStatementAnalyzerTest method test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes.

@Test
public void test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes() throws Exception {
    var executor = SQLExecutor.builder(clusterService).addTable("create table test (shape GEO_SHAPE)").build();
    String stmt = "SELECT * FROM test WHERE MATCH (shape, 'POINT(1.2 1.3)')";
    QueriedSelectRelation rel = executor.analyze(stmt);
    Symbol where = rel.where();
    assertThat(where, instanceOf(MatchPredicate.class));
    DocTableInfo table = executor.resolveTableInfo("test");
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(executor.nodeCtx, RowGranularity.DOC, null, new DocTableRelation(table));
    Symbol normalized = normalizer.normalize(where, CoordinatorTxnCtx.systemTransactionContext());
    assertThat(normalized, isFunction("match"));
    Function match = (Function) normalized;
    assertThat(match.arguments().get(1).valueType(), is(DataTypes.GEO_SHAPE));
    assertThat(match.info().ident().argumentTypes().get(1), is(DataTypes.GEO_SHAPE));
    BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(Version.V_4_1_8);
    match.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    in.setVersion(Version.V_4_1_8);
    Function serializedTo41 = new Function(in);
    assertThat(serializedTo41.info().ident().argumentTypes().get(1), is(DataTypes.STRING));
}
Also used : DistanceFunction(io.crate.expression.scalar.geo.DistanceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) TryCastFunction(io.crate.expression.scalar.cast.TryCastFunction) ExplicitCastFunction(io.crate.expression.scalar.cast.ExplicitCastFunction) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) DocTableInfo(io.crate.metadata.doc.DocTableInfo) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) AliasSymbol(io.crate.expression.symbol.AliasSymbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) DocTableRelation(io.crate.analyze.relations.DocTableRelation) BitString(io.crate.sql.tree.BitString) MatchPredicate(io.crate.expression.symbol.MatchPredicate) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 63 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class PartitionPropertiesAnalyzerTest method testPartitionNameFromAssignmentWithBytesRef.

@Test
public void testPartitionNameFromAssignmentWithBytesRef() {
    DocTableInfo tableInfo = SQLExecutor.partitionedTableInfo(new RelationName("doc", "users"), "create table doc.users (name text primary key) partitioned by (name)", clusterService);
    PartitionName partitionName = getPartitionName(tableInfo);
    assertThat(partitionName.values(), Matchers.contains("foo"));
    assertThat(partitionName.asIndexName(), is(".partitioned.users.0426crrf"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 64 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class PartitionPropertiesAnalyzerTest method testPartitionNameOnRegularTable.

@Test
public void testPartitionNameOnRegularTable() {
    DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "users"), "create table doc.users (name text primary key)", clusterService);
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("table 'doc.users' is not partitioned");
    getPartitionName(tableInfo);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 65 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class MetadataToASTNodeResolverTest method test_bit_string_length_is_shown_in_show_create_table_output.

@Test
public void test_bit_string_length_is_shown_in_show_create_table_output() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table tbl (xs bit(8))").build();
    DocTableInfo table = e.resolveTableInfo("tbl");
    CreateTable<?> node = MetadataToASTNodeResolver.resolveCreateTable(table);
    assertThat(SqlFormatter.formatSql(node), Matchers.containsString("\"xs\" BIT(8)"));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SQLExecutor(io.crate.testing.SQLExecutor) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

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