use of io.crate.metadata.Reference in project crate by crate.
the class SysNodesExpressionsOnHandlerTest method testName.
@Test
public void testName() throws Exception {
Reference refInfo = refInfo("sys.nodes.name", DataTypes.STRING, RowGranularity.NODE);
collectExpression = resolver.getImplementation(refInfo);
collectExpression.setNextRow(CONTEXT);
assertThat(BytesRefs.toBytesRef("crate1"), is(collectExpression.value()));
}
use of io.crate.metadata.Reference in project crate by crate.
the class SysNodesExpressionsOnHandlerTest method testMemory.
@Test
public void testMemory() throws Exception {
Reference refInfo = refInfo("sys.nodes.mem", DataTypes.OBJECT, RowGranularity.NODE);
collectExpression = resolver.getImplementation(refInfo);
collectExpression.setNextRow(CONTEXT);
Map<String, Object> v = (Map<String, Object>) collectExpression.value();
assertThat(v.get("free"), is(12345342234L));
assertThat(v.get("free_percent"), is(Short.valueOf("78")));
assertThat(v.get("used"), is(12345342234L));
assertThat(v.get("used_percent"), is(Short.valueOf("22")));
}
use of io.crate.metadata.Reference in project crate by crate.
the class TableFunctionCollectSource method getCollector.
@Override
public CrateCollector getCollector(CollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
TableFunctionCollectPhase phase = (TableFunctionCollectPhase) collectPhase;
WhereClause whereClause = phase.whereClause();
if (whereClause.noMatch()) {
return RowsCollector.empty(consumer);
}
TableFunctionImplementation functionImplementation = phase.relation().functionImplementation();
TableInfo tableInfo = functionImplementation.createTableInfo(clusterService);
//noinspection unchecked Only literals can be passed to table functions. Anything else is invalid SQL
List<Input<?>> inputs = (List<Input<?>>) (List) phase.relation().function().arguments();
List<Reference> columns = new ArrayList<>(tableInfo.columns());
List<Input<?>> topLevelInputs = new ArrayList<>(phase.toCollect().size());
InputFactory.Context<InputCollectExpression> ctx = inputFactory.ctxForRefs(i -> new InputCollectExpression(columns.indexOf(i)));
for (Symbol symbol : phase.toCollect()) {
topLevelInputs.add(ctx.add(symbol));
}
Iterable<Row> rows = Iterables.transform(functionImplementation.execute(inputs), new ValueAndInputRow<>(topLevelInputs, ctx.expressions()));
if (whereClause.hasQuery()) {
Input<Boolean> condition = (Input<Boolean>) ctx.add(whereClause.query());
rows = Iterables.filter(rows, InputCondition.asPredicate(condition));
}
OrderBy orderBy = phase.orderBy();
if (orderBy != null) {
rows = RowsTransformer.sortRows(Iterables.transform(rows, Row::materialize), phase);
}
return RowsCollector.forRows(rows, phase.toCollect().size(), consumer);
}
use of io.crate.metadata.Reference in project crate by crate.
the class ShardUpsertRequestTest method testStreaming.
@Test
public void testStreaming() throws Exception {
ShardId shardId = new ShardId("test", 1);
String[] assignmentColumns = new String[] { "id", "name" };
UUID jobId = UUID.randomUUID();
Reference[] missingAssignmentColumns = new Reference[] { ID_REF, NAME_REF };
ShardUpsertRequest request = new ShardUpsertRequest.Builder(false, false, assignmentColumns, missingAssignmentColumns, jobId, false).newRequest(shardId, "42");
request.validateConstraints(false);
request.add(123, new ShardUpsertRequest.Item("99", null, new Object[] { 99, new BytesRef("Marvin") }, null));
request.add(5, new ShardUpsertRequest.Item("42", new Symbol[] { Literal.of(42), Literal.of("Deep Thought") }, null, 2L));
BytesStreamOutput out = new BytesStreamOutput();
request.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
ShardUpsertRequest request2 = new ShardUpsertRequest();
request2.readFrom(in);
assertThat(request, equalTo(request2));
}
use of io.crate.metadata.Reference in project crate by crate.
the class DeleteStatementPlanner method collectWithDeleteProjection.
private static Plan collectWithDeleteProjection(TableInfo tableInfo, WhereClause whereClause, Planner.Context plannerContext) {
// for delete, we always need to collect the `_uid`
Reference idReference = tableInfo.getReference(DocSysColumns.ID);
DeleteProjection deleteProjection = new DeleteProjection(new InputColumn(0, DataTypes.STRING));
Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), ImmutableList.of(idReference), ImmutableList.of(deleteProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
Aggregations