Search in sources :

Example 1 with WatermarkedFields

use of com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields in project hazelcast by hazelcast.

the class AggregateSlidingWindowPhysicalRule method findWatermarkedField.

/**
 * Extract watermarked column index
 * (possibly) enforced by IMPOSE_ORDER.
 *
 * @return watermarked column index.
 */
@Nullable
private static Integer findWatermarkedField(AggregateLogicalRel logicalAggregate, RelNode input) {
    // TODO: [viliam, sasha] besides watermark order, we can also use normal collation
    HazelcastRelMetadataQuery query = OptUtils.metadataQuery(input);
    WatermarkedFields watermarkedFields = query.extractWatermarkedFields(input);
    if (watermarkedFields == null) {
        return null;
    }
    Entry<Integer, RexNode> watermarkedField = watermarkedFields.findFirst(logicalAggregate.getGroupSet());
    return watermarkedField != null ? watermarkedField.getKey() : null;
}
Also used : WatermarkedFields(com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields) HazelcastRelMetadataQuery(com.hazelcast.jet.sql.impl.opt.metadata.HazelcastRelMetadataQuery) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 2 with WatermarkedFields

use of com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields in project hazelcast by hazelcast.

the class SlidingWindowAggregatePhysicalRel method watermarkedFields.

public WatermarkedFields watermarkedFields() {
    Map<Integer, RexNode> propertiesByIndex = new HashMap<>();
    RexBuilder rexBuilder = getCluster().getRexBuilder();
    for (Integer index : windowEndIndexes) {
        propertiesByIndex.put(index, rexBuilder.makeInputRef(getInput(), index));
    }
    // Backlog: also support windowStartIndexes by adding windowSize to windowStart
    return new WatermarkedFields(propertiesByIndex);
}
Also used : WatermarkedFields(com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields) HashMap(java.util.HashMap) RexBuilder(org.apache.calcite.rex.RexBuilder) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with WatermarkedFields

use of com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields in project hazelcast by hazelcast.

the class CalciteSqlOptimizer method detectStandaloneImposeOrder.

// The IMPOSE_ORDER function must also drop late items. We don't have this implemented,
// therefore we detect if, besides IMPOSE_ORDER, there's also streaming window aggregation.
// If not, we throw an error. But we don't cover all cases...
private void detectStandaloneImposeOrder(RelNode rel) {
    HazelcastRelMetadataQuery mq = HazelcastRelMetadataQuery.reuseOrCreate(rel.getCluster().getMetadataQuery());
    WatermarkedFields wm = mq.extractWatermarkedFields(rel);
    if (wm != null && !wm.isEmpty()) {
        StreamingAggregationDetector detector = new StreamingAggregationDetector();
        detector.go(rel);
        if (!detector.found) {
            throw QueryException.error("Currently, IMPOSE_ORDER can only be used with window aggregation");
        }
    }
}
Also used : WatermarkedFields(com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields) HazelcastRelMetadataQuery(com.hazelcast.jet.sql.impl.opt.metadata.HazelcastRelMetadataQuery)

Aggregations

WatermarkedFields (com.hazelcast.jet.sql.impl.opt.metadata.WatermarkedFields)3 HazelcastRelMetadataQuery (com.hazelcast.jet.sql.impl.opt.metadata.HazelcastRelMetadataQuery)2 RexNode (org.apache.calcite.rex.RexNode)2 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1