Search in sources :

Example 1 with Row

use of com.hazelcast.sql.impl.row.Row 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;
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Row(com.hazelcast.sql.impl.row.Row) Nullable(javax.annotation.Nullable)

Example 2 with Row

use of com.hazelcast.sql.impl.row.Row 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);
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Row(com.hazelcast.sql.impl.row.Row) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Nullable(javax.annotation.Nullable)

Example 3 with Row

use of com.hazelcast.sql.impl.row.Row in project hazelcast by hazelcast.

the class Projector method project.

Object project(JetSqlRow values) {
    Row row = values.getRow();
    target.init();
    for (int i = 0; i < injectors.length; i++) {
        Object projected = evaluate(projection.get(i), row, evalContext);
        Object value = getToConverter(types[i]).convert(projected);
        injectors[i].set(value);
    }
    return target.conclude();
}
Also used : JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow) Row(com.hazelcast.sql.impl.row.Row)

Aggregations

JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)3 Row (com.hazelcast.sql.impl.row.Row)3 Nullable (javax.annotation.Nullable)2