Search in sources :

Example 11 with InputFactory

use of io.crate.expression.InputFactory 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)

Example 12 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class ProjectionToProjectorVisitorTest method prepare.

@Before
public void prepare() {
    nodeCtx = createNodeContext();
    MockitoAnnotations.initMocks(this);
    visitor = new ProjectionToProjectorVisitor(clusterService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoneCircuitBreakerService(), nodeCtx, THREAD_POOL, Settings.EMPTY, mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS), new InputFactory(nodeCtx), EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx), t -> null, t -> null);
    memoryManager = new OnHeapMemoryManager(usedBytes -> {
    });
    avgSignature = Signature.aggregate("avg", DataTypes.INTEGER.getTypeSignature(), DataTypes.DOUBLE.getTypeSignature());
}
Also used : TransactionContext(io.crate.metadata.TransactionContext) Arrays(java.util.Arrays) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) NodeLimits(io.crate.execution.jobs.NodeLimits) Projector(io.crate.data.Projector) MockitoAnnotations(org.mockito.MockitoAnnotations) Settings(org.elasticsearch.common.settings.Settings) Is.is(org.hamcrest.core.Is.is) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) Bucket(io.crate.data.Bucket) NodeContext(io.crate.metadata.NodeContext) Aggregation(io.crate.expression.symbol.Aggregation) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) SortingProjector(io.crate.execution.engine.sort.SortingProjector) UUID(java.util.UUID) EqOperator(io.crate.expression.operator.EqOperator) Signature(io.crate.metadata.functions.Signature) RandomizedTest.$(com.carrotsearch.randomizedtesting.RandomizedTest.$) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Row(io.crate.data.Row) Matchers.contains(org.hamcrest.Matchers.contains) Symbol(io.crate.expression.symbol.Symbol) AggregateMode(io.crate.expression.symbol.AggregateMode) DataTypes(io.crate.types.DataTypes) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) CountAggregation(io.crate.execution.engine.aggregation.impl.CountAggregation) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Mockito.mock(org.mockito.Mockito.mock) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) InputColumn(io.crate.expression.symbol.InputColumn) SENTINEL(io.crate.data.SentinelRow.SENTINEL) BatchIterator(io.crate.data.BatchIterator) SearchPath(io.crate.metadata.SearchPath) ArrayList(java.util.ArrayList) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) SortingTopNProjector(io.crate.execution.engine.sort.SortingTopNProjector) Before(org.junit.Before) Answers(org.mockito.Answers) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) Test(org.junit.Test) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) Function(io.crate.expression.symbol.Function) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) RamAccounting(io.crate.breaker.RamAccounting) TransportActionProvider(io.crate.execution.TransportActionProvider) TestingBatchIterators(io.crate.testing.TestingBatchIterators) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CollectionBucket(io.crate.data.CollectionBucket) RowGranularity(io.crate.metadata.RowGranularity) Literal(io.crate.expression.symbol.Literal) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) AggregationPipe(io.crate.execution.engine.aggregation.AggregationPipe) InputFactory(io.crate.expression.InputFactory) Collections(java.util.Collections) InputFactory(io.crate.expression.InputFactory) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) NodeLimits(io.crate.execution.jobs.NodeLimits) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 13 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class ProjectorsTest method prepare.

@Before
public void prepare() throws Exception {
    nodeCtx = createNodeContext();
    memoryManager = new OnHeapMemoryManager(bytes -> {
    });
    projectorFactory = new ProjectionToProjectorVisitor(clusterService, new NodeLimits(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), new NoneCircuitBreakerService(), nodeCtx, THREAD_POOL, Settings.EMPTY, mock(TransportActionProvider.class, Answers.RETURNS_DEEP_STUBS), new InputFactory(nodeCtx), new EvaluatingNormalizer(nodeCtx, RowGranularity.SHARD, r -> Literal.ofUnchecked(r.valueType(), r.valueType().sanitizeValue("1")), null), t -> null, t -> null, Version.CURRENT, new ShardId("dummy", UUID.randomUUID().toString(), 0), null);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) InputColumn(io.crate.expression.symbol.InputColumn) Arrays(java.util.Arrays) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) NodeLimits(io.crate.execution.jobs.NodeLimits) ArrayList(java.util.ArrayList) Settings(org.elasticsearch.common.settings.Settings) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) TestingHelpers.createNodeContext(io.crate.testing.TestingHelpers.createNodeContext) Before(org.junit.Before) NodeContext(io.crate.metadata.NodeContext) Answers(org.mockito.Answers) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) Test(org.junit.Test) UUID(java.util.UUID) RamAccounting(io.crate.breaker.RamAccounting) TransportActionProvider(io.crate.execution.TransportActionProvider) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) RowGranularity(io.crate.metadata.RowGranularity) Version(org.elasticsearch.Version) Literal(io.crate.expression.symbol.Literal) AggregateMode(io.crate.expression.symbol.AggregateMode) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) Matchers.is(org.hamcrest.Matchers.is) InputFactory(io.crate.expression.InputFactory) Collections(java.util.Collections) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Mockito.mock(org.mockito.Mockito.mock) ShardId(org.elasticsearch.index.shard.ShardId) InputFactory(io.crate.expression.InputFactory) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) NodeLimits(io.crate.execution.jobs.NodeLimits) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 14 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class MapRowUsingInputsTest method createInputs.

@Before
public void createInputs() throws Exception {
    InputFactory inputFactory = new InputFactory(createNodeContext());
    InputFactory.Context<CollectExpression<Row, ?>> ctx = inputFactory.ctxForInputColumns(txnCtx);
    var addFunction = new Function(Signature.scalar(ArithmeticFunctions.Names.ADD, DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature()).withFeatures(Scalar.DETERMINISTIC_AND_COMPARISON_REPLACEMENT), List.of(new InputColumn(0, DataTypes.LONG), Literal.of(2L)), DataTypes.LONG);
    inputs = Collections.singletonList(ctx.add(addFunction));
    expressions = ctx.expressions();
}
Also used : InputFactory(io.crate.expression.InputFactory) Function(io.crate.expression.symbol.Function) InputColumn(io.crate.expression.symbol.InputColumn) CollectExpression(io.crate.execution.engine.collect.CollectExpression) Before(org.junit.Before)

Example 15 with InputFactory

use of io.crate.expression.InputFactory in project crate by crate.

the class FileReadingCollectorTest method prepare.

@Before
public void prepare() throws Exception {
    NodeContext nodeCtx = new NodeContext(new Functions(Map.of()));
    inputFactory = new InputFactory(nodeCtx);
}
Also used : InputFactory(io.crate.expression.InputFactory) NodeContext(io.crate.metadata.NodeContext) Functions(io.crate.metadata.Functions) Before(org.junit.Before)

Aggregations

InputFactory (io.crate.expression.InputFactory)26 Symbol (io.crate.expression.symbol.Symbol)13 ArrayList (java.util.ArrayList)13 Before (org.junit.Before)10 RamAccounting (io.crate.breaker.RamAccounting)8 Input (io.crate.data.Input)8 NodeContext (io.crate.metadata.NodeContext)8 Test (org.junit.Test)8 Row (io.crate.data.Row)7 OrderBy (io.crate.analyze.OrderBy)6 BatchIterator (io.crate.data.BatchIterator)6 CollectExpression (io.crate.execution.engine.collect.CollectExpression)6 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 Nullable (javax.annotation.Nullable)6 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)5 SENTINEL (io.crate.data.SentinelRow.SENTINEL)5 NodeLimits (io.crate.execution.jobs.NodeLimits)5 InputColumn (io.crate.expression.symbol.InputColumn)5 Functions (io.crate.metadata.Functions)5