use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.
the class PlanExecutor method execute.
SqlResult execute(ShowStatementPlan plan) {
Stream<String> rows;
switch(plan.getShowTarget()) {
case MAPPINGS:
rows = catalog.getMappingNames().stream();
break;
case VIEWS:
rows = catalog.getViewNames().stream();
break;
case JOBS:
assert plan.getShowTarget() == ShowStatementTarget.JOBS;
NodeEngine nodeEngine = getNodeEngine(hazelcastInstance);
JetServiceBackend jetServiceBackend = nodeEngine.getService(JetServiceBackend.SERVICE_NAME);
rows = jetServiceBackend.getJobRepository().getJobRecords().stream().map(record -> record.getConfig().getName()).filter(Objects::nonNull);
break;
default:
throw new AssertionError("Unsupported SHOW statement target.");
}
SqlRowMetadata metadata = new SqlRowMetadata(singletonList(new SqlColumnMetadata("name", VARCHAR, false)));
InternalSerializationService serializationService = Util.getSerializationService(hazelcastInstance);
return new SqlResultImpl(QueryId.create(hazelcastInstance.getLocalEndpoint().getUuid()), new StaticQueryResultProducerImpl(rows.sorted().map(name -> new JetSqlRow(serializationService, new Object[] { name })).iterator()), metadata, false);
}
use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.
the class ExpressionUtil method join.
/**
* Concatenates {@code leftRow} and {@code rightRow} into one, evaluates
* the {@code predicate} on it, and if the predicate passed, returns the
* joined row; returns {@code null} if the predicate didn't pass.
*/
@Nullable
public static JetSqlRow join(@Nonnull JetSqlRow leftRow, @Nonnull JetSqlRow rightRow, @Nonnull Expression<Boolean> predicate, @Nonnull ExpressionEvalContext context) {
Object[] joined = Arrays.copyOf(leftRow.getValues(), leftRow.getFieldCount() + rightRow.getFieldCount());
System.arraycopy(rightRow.getValues(), 0, joined, leftRow.getFieldCount(), rightRow.getFieldCount());
JetSqlRow result = new JetSqlRow(context.getSerializationService(), joined);
Row row = result.getRow();
return Boolean.TRUE.equals(evaluate(predicate, row, context)) ? result : null;
}
use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.
the class ExpressionUtil method evaluate.
/**
* Evaluate projection&predicate for a single row. Returns {@code null} if
* the row is rejected by the predicate.
*/
@Nullable
public static JetSqlRow evaluate(@Nullable Expression<Boolean> predicate, @Nullable List<Expression<?>> projection, @Nonnull JetSqlRow values, @Nonnull ExpressionEvalContext context) {
Row row = values.getRow();
if (predicate != null && !Boolean.TRUE.equals(evaluate(predicate, row, context))) {
return null;
}
if (projection == null) {
return values;
}
Object[] result = new Object[projection.size()];
for (int i = 0; i < projection.size(); i++) {
result[i] = evaluate(projection.get(i), row, context);
}
return new JetSqlRow(context.getSerializationService(), result);
}
use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.
the class JoinByEquiJoinProcessorSupplier method join.
private static List<JetSqlRow> join(JetSqlRow left, Set<Entry<Object, Object>> entries, KvRowProjector rightRowProjector, Expression<Boolean> condition, ExpressionEvalContext evalContext) {
List<JetSqlRow> rows = new ArrayList<>();
for (Entry<Object, Object> entry : entries) {
JetSqlRow right = rightRowProjector.project(entry.getKey(), entry.getValue());
if (right == null) {
continue;
}
JetSqlRow joined = ExpressionUtil.join(left, right, condition, evalContext);
if (joined != null) {
rows.add(joined);
}
}
return rows;
}
use of com.hazelcast.sql.impl.row.JetSqlRow in project hazelcast by hazelcast.
the class MapIndexScanP method runSortedIndex.
private boolean runSortedIndex() {
for (; ; ) {
if (pendingItem != null && !tryEmit(pendingItem)) {
return false;
} else {
pendingItem = null;
}
JetSqlRow extreme = null;
int extremeIndex = -1;
for (int i = 0; i < splits.size(); ++i) {
Split split = splits.get(i);
try {
split.peek();
} catch (MissingPartitionException e) {
splits.addAll(splitOnMigration(split));
splits.remove(i--);
continue;
}
if (split.currentRow == null) {
if (split.done()) {
// No more items to read, remove finished split.
splits.remove(i--);
continue;
}
// waiting for more rows from this split
return false;
}
if (extremeIndex < 0 || metadata.getComparator().compare(split.currentRow, splits.get(extremeIndex).currentRow) < 0) {
extremeIndex = i;
extreme = split.currentRow;
}
}
if (extremeIndex < 0) {
assert splits.isEmpty();
return true;
}
pendingItem = extreme;
splits.get(extremeIndex).remove();
}
}
Aggregations