Search in sources :

Example 6 with Functions

use of io.crate.metadata.Functions in project crate by crate.

the class AggregatorTest method setUpFunctions.

@Before
public void setUpFunctions() {
    Functions functions = getFunctions();
    FunctionIdent countAggIdent = new FunctionIdent(CountAggregation.NAME, Arrays.<DataType>asList(DataTypes.STRING));
    countImpl = (AggregationFunction) functions.get(countAggIdent);
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) TestingHelpers.getFunctions(io.crate.testing.TestingHelpers.getFunctions) Functions(io.crate.metadata.Functions) Before(org.junit.Before)

Example 7 with Functions

use of io.crate.metadata.Functions in project crate by crate.

the class MapSideDataCollectOperationTest method testFileUriCollect.

@Test
public void testFileUriCollect() throws Exception {
    ClusterService clusterService = new NoopClusterService();
    Functions functions = getFunctions();
    CollectSourceResolver collectSourceResolver = mock(CollectSourceResolver.class);
    when(collectSourceResolver.getService(any(RoutedCollectPhase.class))).thenReturn(new FileCollectSource(functions, clusterService, Collections.<String, FileInputFactory>emptyMap()));
    MapSideDataCollectOperation collectOperation = new MapSideDataCollectOperation(collectSourceResolver, threadPool);
    File tmpFile = temporaryFolder.newFile("fileUriCollectOperation.json");
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
        writer.write("{\"name\": \"Arthur\", \"id\": 4, \"details\": {\"age\": 38}}\n");
        writer.write("{\"id\": 5, \"name\": \"Trillian\", \"details\": {\"age\": 33}}\n");
    }
    FileUriCollectPhase collectNode = new FileUriCollectPhase(UUID.randomUUID(), 0, "test", Collections.singletonList("noop_id"), Literal.of(Paths.get(tmpFile.toURI()).toUri().toString()), Arrays.<Symbol>asList(createReference("name", DataTypes.STRING), createReference(new ColumnIdent("details", "age"), DataTypes.INTEGER)), Collections.emptyList(), null, false);
    String threadPoolName = JobCollectContext.threadPoolName(collectNode, "noop_id");
    TestingBatchConsumer consumer = new TestingBatchConsumer();
    JobCollectContext jobCollectContext = mock(JobCollectContext.class);
    CrateCollector collectors = collectOperation.createCollector(collectNode, consumer, jobCollectContext);
    collectOperation.launchCollector(collectors, threadPoolName);
    assertThat(new CollectionBucket(consumer.getResult()), contains(isRow("Arthur", 38), isRow("Trillian", 33)));
}
Also used : CollectSourceResolver(io.crate.operation.collect.sources.CollectSourceResolver) Functions(io.crate.metadata.Functions) FileUriCollectPhase(io.crate.planner.node.dql.FileUriCollectPhase) ColumnIdent(io.crate.metadata.ColumnIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) FileCollectSource(io.crate.operation.collect.sources.FileCollectSource) FileOutputStream(java.io.FileOutputStream) FileInputFactory(io.crate.operation.collect.files.FileInputFactory) OutputStreamWriter(java.io.OutputStreamWriter) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) File(java.io.File) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with Functions

use of io.crate.metadata.Functions in project crate by crate.

the class CurrentSchemaFunctionTest method testNormalizeCurrentSchemaDefaultSchema.

@Test
public void testNormalizeCurrentSchemaDefaultSchema() throws Exception {
    sqlExpressions = new SqlExpressions(tableSources, new SessionContext(0, Option.NONE, null));
    functions = sqlExpressions.getInstance(Functions.class);
    assertNormalize("current_schema()", isLiteral("doc"), false);
}
Also used : SessionContext(io.crate.action.sql.SessionContext) Functions(io.crate.metadata.Functions) SqlExpressions(io.crate.testing.SqlExpressions) AbstractScalarFunctionsTest(io.crate.operation.scalar.AbstractScalarFunctionsTest) Test(org.junit.Test)

Aggregations

Functions (io.crate.metadata.Functions)8 SqlExpressions (io.crate.testing.SqlExpressions)3 SessionContext (io.crate.action.sql.SessionContext)2 AggregationImplModule (io.crate.operation.aggregation.impl.AggregationImplModule)2 AbstractScalarFunctionsTest (io.crate.operation.scalar.AbstractScalarFunctionsTest)2 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 EvaluatingNormalizer (io.crate.analyze.EvaluatingNormalizer)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 BatchConsumer (io.crate.data.BatchConsumer)1 CollectionBucket (io.crate.data.CollectionBucket)1 Row (io.crate.data.Row)1 RowsBatchIterator (io.crate.data.RowsBatchIterator)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 FunctionIdent (io.crate.metadata.FunctionIdent)1 ReplaceMode (io.crate.metadata.ReplaceMode)1 RowGranularity (io.crate.metadata.RowGranularity)1