use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class TestingHelpers method refInfo.
public static Reference refInfo(String fqColumnName, DataType dataType, RowGranularity rowGranularity, String... nested) {
String[] parts = fqColumnName.split("\\.");
ReferenceIdent refIdent;
List<String> nestedParts = null;
if (nested.length > 0) {
nestedParts = Arrays.asList(nested);
}
switch(parts.length) {
case 2:
refIdent = new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, parts[0]), parts[1], nestedParts);
break;
case 3:
refIdent = new ReferenceIdent(new RelationName(parts[0], parts[1]), parts[2], nestedParts);
break;
default:
throw new IllegalArgumentException("fqColumnName must contain <table>.<column> or <schema>.<table>.<column>");
}
return new Reference(refIdent, rowGranularity, dataType, 0, null);
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class DocValuesGroupByOptimizedIteratorTest method test_group_by_doc_values_optimized_iterator_for_many_keys.
@Test
public void test_group_by_doc_values_optimized_iterator_for_many_keys() throws Exception {
SumAggregation<?> sumAggregation = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.LONG), DataTypes.LONG);
var sumDocValuesAggregator = sumAggregation.getDocValueAggregator(List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "z"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null)), mock(DocTableInfo.class), List.of());
var keyExpressions = List.of(new BytesRefColumnReference("x"), new LongColumnReference("y"));
var keyRefs = List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "x"), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 1, null), new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "y"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 2, null));
var it = DocValuesGroupByOptimizedIterator.GroupByIterator.forManyKeys(List.of(sumDocValuesAggregator), indexSearcher, keyRefs, keyExpressions, RamAccounting.NO_ACCOUNTING, null, null, new MatchAllDocsQuery(), new CollectorContext());
var rowConsumer = new TestingRowConsumer();
rowConsumer.accept(it, null);
assertThat(rowConsumer.getResult(), containsInAnyOrder(new Object[] { "0", 0L, 6L }, new Object[] { "1", 1L, 4L }));
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class SymbolPrinterTest method testDocReference.
@Test
public void testDocReference() throws Exception {
Reference r = new Reference(new ReferenceIdent(new RelationName("doc", "table"), new ColumnIdent("column", Arrays.asList("path", "nested"))), RowGranularity.DOC, DataTypes.STRING, 0, null);
assertPrint(r, "doc.\"table\".\"column\"['path']['nested']");
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.
@Test
public void testInsertFromQueryWithPartitionedColumn() {
Merge planNode = e.plan("insert into users (id, date) (select id, date from parted_pks)");
Collect queryAndFetch = (Collect) planNode.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) queryAndFetch.collectPhase());
List<Symbol> toCollect = collectPhase.toCollect();
assertThat(toCollect.size(), is(2));
assertThat(toCollect.get(0), isReference("_doc['id']"));
assertThat(toCollect.get(1), equalTo(new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "parted_pks"), "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMPZ, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 3, null)));
}
use of io.crate.metadata.ReferenceIdent in project crate by crate.
the class ExpressionAnalyzerTest method testAnalyzeArraySliceFunctionCall.
@Test
public void testAnalyzeArraySliceFunctionCall() {
ReferenceIdent arrayRefIdent = new ReferenceIdent(new RelationName("doc", "tarr"), "xs");
Reference arrayRef = new Reference(arrayRefIdent, RowGranularity.DOC, DataTypes.INTEGER_ARRAY, ColumnPolicy.DYNAMIC, Reference.IndexType.PLAIN, true, true, 1, null);
CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
ExpressionAnalysisContext localContext = new ExpressionAnalysisContext(txnCtx.sessionContext());
Symbol function = ExpressionAnalyzer.allocateFunction(ArraySliceFunction.NAME, List.of(arrayRef, Literal.of(1), Literal.of(3)), null, localContext, txnCtx, expressions.nodeCtx);
var result = executor.asSymbol("tarr.xs[1:3]");
assertThat(result, is(equalTo(function)));
}
Aggregations