Search in sources :

Example 56 with DocTableInfo

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

the class SymbolPrinterTest method prepare.

@Before
public void prepare() throws Exception {
    String createTableStmt = "create table doc.formatter (" + "  foo text," + "  bar bigint," + "  \"CraZy\" ip," + "  \"1a\" int," + "  \"select\" char," + "  idx int," + "  s_arr array(text)" + ")";
    RelationName name = new RelationName(DocSchemaInfo.NAME, TABLE_NAME);
    DocTableInfo tableInfo = SQLExecutor.tableInfo(name, createTableStmt, clusterService);
    Map<RelationName, AnalyzedRelation> sources = Map.of(name, new TableRelation(tableInfo));
    sqlExpressions = new SqlExpressions(sources);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) Before(org.junit.Before)

Example 57 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 58 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 59 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 60 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)

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