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)));
}
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);
}
use of io.crate.metadata.Functions in project crate by crate.
the class GroupingLongCollectorBenchmark method createGroupingCollector.
@Setup
public void createGroupingCollector() throws Exception {
IndexWriter iw = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer()));
Functions functions = new ModulesBuilder().add(new AggregationImplModule()).createInjector().getInstance(Functions.class);
SumAggregation<?> sumAgg = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.INTEGER.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.INTEGER), DataTypes.INTEGER);
var memoryManager = new OnHeapMemoryManager(bytes -> {
});
groupBySumCollector = createGroupBySumCollector(sumAgg, memoryManager);
int size = 20_000_000;
rows = new ArrayList<>(size);
numbers = new long[size];
for (int i = 0; i < size; i++) {
long value = (long) i % 200;
rows.add(new Row1(value));
numbers[i] = value;
var doc = new Document();
doc.add(new NumericDocValuesField("x", value));
doc.add(new SortedNumericDocValuesField("y", value));
iw.addDocument(doc);
}
iw.commit();
iw.forceMerge(1, true);
searcher = new IndexSearcher(DirectoryReader.open(iw));
}
use of io.crate.metadata.Functions in project crate by crate.
the class SQLIntegrationTestCase method assertFunctionIsCreatedOnAll.
public void assertFunctionIsCreatedOnAll(String schema, String name, List<DataType<?>> argTypes) throws Exception {
SearchPath searchPath = SearchPath.pathWithPGCatalogAndDoc();
assertBusy(() -> {
Iterable<Functions> functions = internalCluster().getInstances(Functions.class);
for (Functions function : functions) {
FunctionImplementation func = function.get(schema, name, Lists2.map(argTypes, t -> Literal.of(t, null)), searchPath);
assertThat(func, is(not(nullValue())));
assertThat(func.info().ident().argumentTypes(), is(equalTo(argTypes)));
}
}, 20L, TimeUnit.SECONDS);
}
Aggregations