Search in sources :

Example 1 with HazelcastRelMetadataQuery

use of com.hazelcast.jet.sql.impl.opt.metadata.HazelcastRelMetadataQuery 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 HazelcastRelMetadataQuery

use of com.hazelcast.jet.sql.impl.opt.metadata.HazelcastRelMetadataQuery 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

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