Search in sources :

Example 26 with DocTableInfo

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

the class UpdateAnalyzerTest method testUpdateInvalidType.

@Test
public void testUpdateInvalidType() throws Exception {
    Object[] params = { new Object[] { new Object[] { "a", "b" } } };
    AnalyzedUpdateStatement update = analyze("update users set tags=? where id=1");
    expectedException.expect(ConversionException.class);
    expectedException.expectMessage("Cannot cast value `[[a, b]]` to type `text_array`");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) RowN(io.crate.data.RowN) Assignments(io.crate.expression.symbol.Assignments) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 27 with DocTableInfo

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

the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParam.

@Test
public void testUpdateDynamicNestedArrayParam() throws Exception {
    Object[] params = { new Object[] { new Object[] { 1.9, 4.8 }, new Object[] { 9.7, 12.7 } } };
    AnalyzedUpdateStatement update = analyze("update users set new=? where id=1");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
    DataType dataType = sources[0].valueType();
    assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RowN(io.crate.data.RowN) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) Assignments(io.crate.expression.symbol.Assignments) DataType(io.crate.types.DataType) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 28 with DocTableInfo

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

the class UpdateAnalyzerTest method testUpdateWithEmptyObjectArray.

@Test
public void testUpdateWithEmptyObjectArray() throws Exception {
    Object[] params = { new Map[0], 0 };
    AnalyzedUpdateStatement update = analyze("update users set friends=? where other_id=0");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
    assertThat(sources[0].valueType().id(), is(ArrayType.ID));
    assertThat(((ArrayType) sources[0].valueType()).innerType().id(), is(ObjectType.ID));
    assertThat(((List) ((Literal) sources[0]).value()).size(), is(0));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RowN(io.crate.data.RowN) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) Assignments(io.crate.expression.symbol.Assignments) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 29 with DocTableInfo

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

the class UpdateAnalyzerTest method testUpdateAssignmentConvertableType.

@Test
public void testUpdateAssignmentConvertableType() throws Exception {
    AnalyzedUpdateStatement update = analyze("update users set other_id=9.9");
    Reference ref = update.assignmentByTargetCol().keySet().iterator().next();
    assertThat(ref, not(instanceOf(DynamicReference.class)));
    assertEquals(DataTypes.LONG, ref.valueType());
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), Row.EMPTY, SubQueryResults.EMPTY);
    assertThat(sources[0], isLiteral(9L));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) DynamicReference(io.crate.expression.symbol.DynamicReference) Reference(io.crate.metadata.Reference) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) Assignments(io.crate.expression.symbol.Assignments) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 30 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)

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