Search in sources :

Example 1 with DocRefResolver

use of io.crate.expression.reference.DocRefResolver in project crate by crate.

the class GeneratedColumnsTest method testSubscriptExpressionThatReturnsAnArray.

@Test
public void testSubscriptExpressionThatReturnsAnArray() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addTable("create table t (obj object as (arr array(integer)), arr as obj['arr'])").build();
    QueriedSelectRelation query = e.analyze("select obj, arr from t");
    DocTableInfo table = ((DocTableRelation) query.from().get(0)).tableInfo();
    GeneratedColumns<Doc> generatedColumns = new GeneratedColumns<>(new InputFactory(e.nodeCtx), CoordinatorTxnCtx.systemTransactionContext(), GeneratedColumns.Validation.NONE, new DocRefResolver(Collections.emptyList()), Collections.emptyList(), table.generatedColumns());
    BytesReference bytes = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().startObject("obj").startArray("arr").value(10).value(20).endArray().endObject().endObject());
    generatedColumns.setNextRow(new Doc(1, table.concreteIndices()[0], "1", 1, 1, 1, XContentHelper.convertToMap(bytes, false, XContentType.JSON).v2(), bytes::utf8ToString));
    Map.Entry<Reference, Input<?>> generatedColumn = generatedColumns.generatedToInject().iterator().next();
    assertThat((List<Object>) generatedColumn.getValue().value(), contains(10, 20));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) InputFactory(io.crate.expression.InputFactory) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) BytesReference(org.elasticsearch.common.bytes.BytesReference) DocRefResolver(io.crate.expression.reference.DocRefResolver) Input(io.crate.data.Input) SQLExecutor(io.crate.testing.SQLExecutor) QueriedSelectRelation(io.crate.analyze.QueriedSelectRelation) DocTableRelation(io.crate.analyze.relations.DocTableRelation) Doc(io.crate.expression.reference.Doc) Map(java.util.Map) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 Input (io.crate.data.Input)1 InputFactory (io.crate.expression.InputFactory)1 Doc (io.crate.expression.reference.Doc)1 DocRefResolver (io.crate.expression.reference.DocRefResolver)1 Reference (io.crate.metadata.Reference)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 SQLExecutor (io.crate.testing.SQLExecutor)1 Map (java.util.Map)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 Test (org.junit.Test)1