diff --git a/extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/AveragerFactoryWrapper.java b/extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/AveragerFactoryWrapper.java index 9e4118c5669..42cfc3a4a6a 100644 --- a/extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/AveragerFactoryWrapper.java +++ b/extensions-contrib/moving-average-query/src/main/java/org/apache/druid/query/movingaverage/AveragerFactoryWrapper.java @@ -24,6 +24,7 @@ import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.BufferAggregator; import org.apache.druid.query.movingaverage.averagers.AveragerFactory; import org.apache.druid.segment.ColumnSelectorFactory; +import org.apache.druid.segment.column.ValueType; import javax.annotation.Nullable; import java.util.Comparator; @@ -161,12 +162,14 @@ public class AveragerFactoryWrapper extends AggregatorFactory } /** - * Not implemented. Throws UnsupportedOperationException. + * This method must be implemented since it is called by + * {@link org.apache.druid.query.groupby.GroupByQuery#computeResultRowSignature}. Returning "COMPLEX" causes the + * return type to be treated as unknown. */ @Override public String getTypeName() { - throw new UnsupportedOperationException("Invalid operation for AveragerFactoryWrapper."); + return ValueType.COMPLEX.name(); } /** diff --git a/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestGenerateSketchSqlAggregator.java b/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestGenerateSketchSqlAggregator.java index 725f335baee..a7346ffb0ff 100644 --- a/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestGenerateSketchSqlAggregator.java +++ b/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestGenerateSketchSqlAggregator.java @@ -36,13 +36,13 @@ import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorFactory; import org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchUtils; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchQuantileSqlAggregator.java b/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchQuantileSqlAggregator.java index 02231722702..09d8b02feca 100644 --- a/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchQuantileSqlAggregator.java +++ b/extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchQuantileSqlAggregator.java @@ -39,13 +39,13 @@ import org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchAggregatorF import org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchToQuantilePostAggregator; import org.apache.druid.query.aggregation.tdigestsketch.TDigestSketchUtils; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java index 5a406411354..72eed0dadb7 100644 --- a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java +++ b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java @@ -185,8 +185,8 @@ public class TimestampGroupByAggregationTest groupBy ); - int groupByFieldNumber = ((GroupByQuery) helper.readQuery(groupBy)).getResultRowPositionLookup() - .getInt(groupByField); + int groupByFieldNumber = ((GroupByQuery) helper.readQuery(groupBy)).getResultRowSignature() + .indexOf(groupByField); List results = seq.toList(); Assert.assertEquals(36, results.size()); diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java index 1b6719960f9..87ea9038de5 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchBaseSqlAggregator.java @@ -34,6 +34,7 @@ import org.apache.druid.query.aggregation.datasketches.hll.HllSketchMergeAggrega import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -42,7 +43,6 @@ import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; @@ -120,7 +120,7 @@ public abstract class HllSketchBaseSqlAggregator implements SqlAggregator final String aggregatorName = finalizeAggregations ? Calcites.makePrefixedName(name, "a") : name; if (columnArg.isDirectColumnAccess() - && rowSignature.getColumnType(columnArg.getDirectColumn()) == ValueType.COMPLEX) { + && rowSignature.getColumnType(columnArg.getDirectColumn()).orElse(null) == ValueType.COMPLEX) { aggregatorFactory = new HllSketchMergeAggregatorFactory( aggregatorName, columnArg.getDirectColumn(), diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateOperatorConversion.java index 3f6b45ae5d2..11bd15d3ae9 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateOperatorConversion.java @@ -31,12 +31,12 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.hll.HllSketchAggregatorFactory; import org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimatePostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateWithErrorBoundsOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateWithErrorBoundsOperatorConversion.java index 03296819fbd..a0435430c02 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateWithErrorBoundsOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchEstimateWithErrorBoundsOperatorConversion.java @@ -30,12 +30,12 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.hll.HllSketchToEstimateWithBoundsPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java index e01ceb3fc94..2fe6a5e6ebf 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSetUnionOperatorConversion.java @@ -32,13 +32,13 @@ import org.apache.calcite.sql.type.SqlOperandCountRanges; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.hll.HllSketchUnionPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchToStringOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchToStringOperatorConversion.java index 6adbbceb137..189b3b7c916 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchToStringOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchToStringOperatorConversion.java @@ -28,12 +28,12 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.hll.HllSketchToStringPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchApproxQuantileSqlAggregator.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchApproxQuantileSqlAggregator.java index 0b5b9438f6d..47aade4683c 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchApproxQuantileSqlAggregator.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchApproxQuantileSqlAggregator.java @@ -38,6 +38,7 @@ import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAg import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchToQuantilePostAggregator; import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -45,7 +46,6 @@ import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchListArgBaseOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchListArgBaseOperatorConversion.java index 99bcbfcab4b..c9533ef337f 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchListArgBaseOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchListArgBaseOperatorConversion.java @@ -31,13 +31,13 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.type.SqlOperandCountRanges; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchObjectSqlAggregator.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchObjectSqlAggregator.java index 41bed2f3140..70b5eb16cb3 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchObjectSqlAggregator.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchObjectSqlAggregator.java @@ -36,13 +36,13 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSingleArgBaseOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSingleArgBaseOperatorConversion.java index cb08e8fae68..a284c96de11 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSingleArgBaseOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSingleArgBaseOperatorConversion.java @@ -25,12 +25,12 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.SqlOperator; import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSummaryOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSummaryOperatorConversion.java index 210d3308c0c..6465ef71f45 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSummaryOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSummaryOperatorConversion.java @@ -28,12 +28,12 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchToStringPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchBaseSqlAggregator.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchBaseSqlAggregator.java index 8ea95852f3e..ac277ded842 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchBaseSqlAggregator.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchBaseSqlAggregator.java @@ -33,6 +33,7 @@ import org.apache.druid.query.aggregation.datasketches.theta.SketchMergeAggregat import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -41,7 +42,6 @@ import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; @@ -98,7 +98,8 @@ public abstract class ThetaSketchBaseSqlAggregator implements SqlAggregator final AggregatorFactory aggregatorFactory; final String aggregatorName = finalizeAggregations ? Calcites.makePrefixedName(name, "a") : name; - if (columnArg.isDirectColumnAccess() && rowSignature.getColumnType(columnArg.getDirectColumn()) == ValueType.COMPLEX) { + if (columnArg.isDirectColumnAccess() + && rowSignature.getColumnType(columnArg.getDirectColumn()).orElse(null) == ValueType.COMPLEX) { aggregatorFactory = new SketchMergeAggregatorFactory( aggregatorName, columnArg.getDirectColumn(), diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateOperatorConversion.java index aee08952822..48702345cc0 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateOperatorConversion.java @@ -28,12 +28,12 @@ import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.theta.SketchEstimatePostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateWithErrorBoundsOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateWithErrorBoundsOperatorConversion.java index 13800a1a00e..7ddd74ee80c 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateWithErrorBoundsOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchEstimateWithErrorBoundsOperatorConversion.java @@ -30,12 +30,12 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.theta.SketchEstimatePostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java index a86be8b9fe6..5ec31f014a5 100644 --- a/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java +++ b/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSetBaseOperatorConversion.java @@ -33,13 +33,13 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregator.java b/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregator.java index 3b0df6a533b..f1fca86b09f 100644 --- a/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregator.java +++ b/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregator.java @@ -38,6 +38,7 @@ import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.query.dimension.ExtractionDimensionSpec; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.aggregation.Aggregation; @@ -47,7 +48,6 @@ import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/filter/sql/BloomFilterOperatorConversion.java b/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/filter/sql/BloomFilterOperatorConversion.java index 64ec379a2e7..8041f02c90a 100644 --- a/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/filter/sql/BloomFilterOperatorConversion.java +++ b/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/filter/sql/BloomFilterOperatorConversion.java @@ -34,13 +34,13 @@ import org.apache.druid.query.filter.BloomKFilter; import org.apache.druid.query.filter.BloomKFilterHolder; import org.apache.druid.query.filter.DimFilter; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.io.IOException; diff --git a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregator.java b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregator.java index 31efa8f5f2f..cd7e58b15c6 100644 --- a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregator.java +++ b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregator.java @@ -38,6 +38,7 @@ import org.apache.druid.query.aggregation.histogram.FixedBucketsHistogram; import org.apache.druid.query.aggregation.histogram.FixedBucketsHistogramAggregatorFactory; import org.apache.druid.query.aggregation.histogram.QuantilePostAggregator; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -45,7 +46,6 @@ import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregator.java b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregator.java index 84833580c57..44dd9a67c36 100644 --- a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregator.java +++ b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregator.java @@ -39,6 +39,7 @@ import org.apache.druid.query.aggregation.histogram.ApproximateHistogramAggregat import org.apache.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregatorFactory; import org.apache.druid.query.aggregation.histogram.QuantilePostAggregator; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.aggregation.Aggregation; @@ -47,7 +48,6 @@ import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; @@ -175,7 +175,7 @@ public class QuantileSqlAggregator implements SqlAggregator final List virtualColumns = new ArrayList<>(); if (input.isDirectColumnAccess()) { - if (rowSignature.getColumnType(input.getDirectColumn()) == ValueType.COMPLEX) { + if (rowSignature.getColumnType(input.getDirectColumn()).orElse(null) == ValueType.COMPLEX) { aggregatorFactory = new ApproximateHistogramFoldingAggregatorFactory( histogramName, input.getDirectColumn(), diff --git a/extensions-core/stats/src/main/java/org/apache/druid/query/aggregation/variance/sql/BaseVarianceSqlAggregator.java b/extensions-core/stats/src/main/java/org/apache/druid/query/aggregation/variance/sql/BaseVarianceSqlAggregator.java index 4cdd665b74b..36d1a189ccb 100644 --- a/extensions-core/stats/src/main/java/org/apache/druid/query/aggregation/variance/sql/BaseVarianceSqlAggregator.java +++ b/extensions-core/stats/src/main/java/org/apache/druid/query/aggregation/variance/sql/BaseVarianceSqlAggregator.java @@ -36,6 +36,7 @@ import org.apache.druid.query.aggregation.variance.VarianceAggregatorFactory; import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -44,7 +45,6 @@ import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/processing/src/main/java/org/apache/druid/query/InlineDataSource.java b/processing/src/main/java/org/apache/druid/query/InlineDataSource.java index f8186667d4b..724903e854c 100644 --- a/processing/src/main/java/org/apache/druid/query/InlineDataSource.java +++ b/processing/src/main/java/org/apache/druid/query/InlineDataSource.java @@ -23,16 +23,15 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.druid.java.util.common.IAE; import org.apache.druid.segment.RowAdapter; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.function.Function; @@ -167,18 +166,15 @@ public class InlineDataSource implements DataSource return true; } - public Map getRowSignature() + public RowSignature getRowSignature() { - final ImmutableMap.Builder retVal = ImmutableMap.builder(); + final RowSignature.Builder builder = RowSignature.builder(); for (int i = 0; i < columnNames.size(); i++) { - final ValueType columnType = columnTypes.get(i); - if (columnType != null) { - retVal.put(columnNames.get(i), columnType); - } + builder.add(columnNames.get(i), columnTypes.get(i)); } - return retVal.build(); + return builder.build(); } public RowAdapter rowAdapter() diff --git a/processing/src/main/java/org/apache/druid/query/QueryToolChest.java b/processing/src/main/java/org/apache/druid/query/QueryToolChest.java index b72d9d76eb4..509738ee680 100644 --- a/processing/src/main/java/org/apache/druid/query/QueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/QueryToolChest.java @@ -28,6 +28,7 @@ import org.apache.druid.guice.annotations.ExtensionPoint; import org.apache.druid.java.util.common.UOE; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.aggregation.MetricManipulationFn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.timeline.LogicalSegment; import javax.annotation.Nullable; @@ -286,23 +287,23 @@ public abstract class QueryToolChest resultArrayFields(QueryType query) + public RowSignature resultArraySignature(QueryType query) { throw new UOE("Query type '%s' does not support returning results as arrays", query.getType()); } /** - * Converts a sequence of this query's ResultType into arrays. The array schema is given by - * {@link #resultArrayFields}. This functionality is useful because it allows higher-level processors to operate on + * Converts a sequence of this query's ResultType into arrays. The array signature is given by + * {@link #resultArraySignature}. This functionality is useful because it allows higher-level processors to operate on * the results of any query in a consistent way. This is useful for the SQL layer and for any algorithm that might * operate on the results of an inner query. * diff --git a/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorFactory.java b/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorFactory.java index bb23ff952ec..93f22177120 100644 --- a/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorFactory.java +++ b/processing/src/main/java/org/apache/druid/query/aggregation/AggregatorFactory.java @@ -126,11 +126,11 @@ public abstract class AggregatorFactory implements Cacheable * For simple aggregators, the combining factory may be computed by simply creating a new factory that is the same as * the current, except with its input column renamed to the same as the output column. For example, this aggregator: * - * {"type": "longSum", "fieldName": "foo", "name": "bar"} + * {"type": "longSum", "fieldName": "foo", "name": "bar"} * * Would become: * - * {"type": "longSum", "fieldName": "bar", "name": "bar"} + * {"type": "longSum", "fieldName": "bar", "name": "bar"} * * Sometimes, the type or other parameters of the combining aggregator will be different from the original aggregator. * For example, the {@link CountAggregatorFactory} getCombiningFactory method will return a @@ -209,6 +209,22 @@ public abstract class AggregatorFactory implements Cacheable */ public abstract List requiredFields(); + /** + * Get the type name of the intermediate type for this aggregator. This is the same as the type returned by + * {@link #deserialize} and the type accepted by {@link #combine}. However, it is *not* necessarily the same type + * returned by {@link #finalizeComputation}. + * + * If the type is complex (i.e. not a simple, numeric {@link org.apache.druid.segment.column.ValueType}) then there + * must be a corresponding {@link org.apache.druid.segment.serde.ComplexMetricSerde} which was registered with + * {@link org.apache.druid.segment.serde.ComplexMetrics#registerSerde} using this type name. + * + * If you need a ValueType enum corresponding to this aggregator, a good way to do that is: + * + *
+   *   Optional.ofNullable(GuavaUtils.getEnumIfPresent(ValueType.class, aggregator.getTypeName()))
+   *           .orElse(ValueType.COMPLEX);
+   * 
+ */ public abstract String getTypeName(); /** diff --git a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQuery.java b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQuery.java index 41425b93b20..4c17f16b03a 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQuery.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQuery.java @@ -32,8 +32,6 @@ import com.google.common.collect.Ordering; import com.google.common.primitives.Longs; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.ISE; @@ -66,6 +64,7 @@ import org.apache.druid.segment.DimensionHandlerUtils; import org.apache.druid.segment.VirtualColumn; import org.apache.druid.segment.VirtualColumns; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.joda.time.DateTime; import org.joda.time.Interval; @@ -111,8 +110,7 @@ public class GroupByQuery extends BaseQuery private final boolean applyLimitPushDown; private final Function, Sequence> postProcessingFn; - private final List resultRowOrder; - private final Object2IntMap resultRowPositionLookup; + private final RowSignature resultRowSignature; /** * This is set when we know that all rows will have the same timestamp, and allows us to not actually store @@ -205,18 +203,16 @@ public class GroupByQuery extends BaseQuery postAggregatorSpecs == null ? ImmutableList.of() : postAggregatorSpecs ); + // Verify no duplicate names between dimensions, aggregators, and postAggregators. + // They will all end up in the same namespace in the returned Rows and we can't have them clobbering each other. + verifyOutputNames(this.dimensions, this.aggregatorSpecs, this.postAggregatorSpecs); + this.universalTimestamp = computeUniversalTimestamp(); - this.resultRowOrder = computeResultRowOrder(); - this.resultRowPositionLookup = computeResultRowOrderLookup(); + this.resultRowSignature = computeResultRowSignature(); this.havingSpec = havingSpec; this.limitSpec = LimitSpec.nullToNoopLimitSpec(limitSpec); this.subtotalsSpec = verifySubtotalsSpec(subtotalsSpec, this.dimensions); - // Verify no duplicate names between dimensions, aggregators, and postAggregators. - // They will all end up in the same namespace in the returned Rows and we can't have them clobbering each other. - // We're not counting __time, even though that name is problematic. See: https://github.com/apache/druid/pull/3684 - verifyOutputNames(this.dimensions, this.aggregatorSpecs, this.postAggregatorSpecs); - this.postProcessingFn = postProcessingFn != null ? postProcessingFn : makePostProcessingFn(); // Check if limit push down configuration is valid and check if limit push down will be applied @@ -310,9 +306,9 @@ public class GroupByQuery extends BaseQuery * * @see ResultRow for documentation about the order that fields will be in */ - public List getResultRowOrder() + public RowSignature getResultRowSignature() { - return resultRowOrder; + return resultRowSignature; } /** @@ -328,16 +324,7 @@ public class GroupByQuery extends BaseQuery */ public int getResultRowSizeWithPostAggregators() { - return resultRowOrder.size(); - } - - /** - * Returns a map that can be used to look up the position within ResultRows of certain field names. The map's - * {@link Object2IntMap#getInt(Object)} method will return -1 if the field is not found. - */ - public Object2IntMap getResultRowPositionLookup() - { - return resultRowPositionLookup; + return resultRowSignature.size(); } /** @@ -470,32 +457,18 @@ public class GroupByQuery extends BaseQuery return forcePushDown; } - private Object2IntMap computeResultRowOrderLookup() + private RowSignature computeResultRowSignature() { - final Object2IntMap indexes = new Object2IntOpenHashMap<>(); - indexes.defaultReturnValue(-1); - - int index = 0; - for (String columnName : resultRowOrder) { - indexes.put(columnName, index++); - } - - return indexes; - } - - private List computeResultRowOrder() - { - final List retVal = new ArrayList<>(); + final RowSignature.Builder builder = RowSignature.builder(); if (universalTimestamp == null) { - retVal.add(ColumnHolder.TIME_COLUMN_NAME); + builder.addTimeColumn(); } - dimensions.stream().map(DimensionSpec::getOutputName).forEach(retVal::add); - aggregatorSpecs.stream().map(AggregatorFactory::getName).forEach(retVal::add); - postAggregatorSpecs.stream().map(PostAggregator::getName).forEach(retVal::add); - - return retVal; + return builder.addDimensions(dimensions) + .addAggregators(aggregatorSpecs) + .addPostAggregators(postAggregatorSpecs) + .build(); } private boolean determineApplyLimitPushDown() @@ -562,7 +535,7 @@ public class GroupByQuery extends BaseQuery int dimIndex = OrderByColumnSpec.getDimIndexForOrderBy(orderSpec, dimensions); if (dimIndex >= 0) { DimensionSpec dim = dimensions.get(dimIndex); - orderedFieldNumbers.add(resultRowPositionLookup.getInt(dim.getOutputName())); + orderedFieldNumbers.add(resultRowSignature.indexOf(dim.getOutputName())); dimsInOrderBy.add(dimIndex); needsReverseList.add(needsReverse); final ValueType type = dimensions.get(dimIndex).getOutputType(); @@ -573,7 +546,7 @@ public class GroupByQuery extends BaseQuery for (int i = 0; i < dimensions.size(); i++) { if (!dimsInOrderBy.contains(i)) { - orderedFieldNumbers.add(resultRowPositionLookup.getInt(dimensions.get(i).getOutputName())); + orderedFieldNumbers.add(resultRowSignature.indexOf(dimensions.get(i).getOutputName())); needsReverseList.add(false); final ValueType type = dimensions.get(i).getOutputType(); dimensionTypes.add(type); diff --git a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryHelper.java b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryHelper.java index ed74800ddc1..877fd34ccf7 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryHelper.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryHelper.java @@ -20,10 +20,8 @@ package org.apache.druid.query.groupby; import com.google.common.base.Function; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.druid.collections.NonBlockingPool; -import org.apache.druid.common.guava.GuavaUtils; import org.apache.druid.data.input.MapBasedInputRow; import org.apache.druid.data.input.MapBasedRow; import org.apache.druid.data.input.Row; @@ -32,7 +30,6 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.Pair; -import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; import org.apache.druid.java.util.common.guava.Accumulator; @@ -42,8 +39,6 @@ import org.apache.druid.query.ResourceLimitExceededException; import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.dimension.DimensionSpec; -import org.apache.druid.segment.RowBasedColumnSelectorFactory; -import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.incremental.IncrementalIndex; import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.incremental.IndexSizeExceededException; @@ -53,7 +48,6 @@ import javax.annotation.Nullable; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -227,39 +221,6 @@ public class GroupByQueryHelper ); } - /** - * Returns types for fields that will appear in the Rows output from "query". Useful for feeding them into - * {@link RowBasedColumnSelectorFactory}. - * - * @param query groupBy query - * - * @return row types - */ - public static Map rowSignatureFor(final GroupByQuery query) - { - final ImmutableMap.Builder types = ImmutableMap.builder(); - - for (DimensionSpec dimensionSpec : query.getDimensions()) { - types.put(dimensionSpec.getOutputName(), dimensionSpec.getOutputType()); - } - - for (AggregatorFactory aggregatorFactory : query.getAggregatorSpecs()) { - final String typeName = aggregatorFactory.getTypeName(); - final ValueType valueType; - if (typeName != null) { - valueType = GuavaUtils.getEnumIfPresent(ValueType.class, StringUtils.toUpperCase(typeName)); - } else { - valueType = null; - } - if (valueType != null) { - types.put(aggregatorFactory.getName(), valueType); - } - } - - // Don't include post-aggregators since we don't know what types they are. - return types.build(); - } - public static ResultRow toResultRow(final GroupByQuery query, final Row row) { final ResultRow resultRow = ResultRow.create(query.getResultRowSizeWithPostAggregators()); diff --git a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java index ebae09f184f..741b8f6dd97 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -62,6 +62,7 @@ import org.apache.druid.query.groupby.resource.GroupByQueryResource; import org.apache.druid.query.groupby.strategy.GroupByStrategy; import org.apache.druid.query.groupby.strategy.GroupByStrategySelector; import org.apache.druid.segment.DimensionHandlerUtils; +import org.apache.druid.segment.column.RowSignature; import org.joda.time.DateTime; import java.io.IOException; @@ -684,9 +685,9 @@ public class GroupByQueryQueryToolChest extends QueryToolChest resultArrayFields(final GroupByQuery query) + public RowSignature resultArraySignature(GroupByQuery query) { - return query.getResultRowOrder(); + return query.getResultRowSignature(); } @Override diff --git a/processing/src/main/java/org/apache/druid/query/groupby/ResultRow.java b/processing/src/main/java/org/apache/druid/query/groupby/ResultRow.java index 138b1e6aa20..977cba96034 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/ResultRow.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/ResultRow.java @@ -26,12 +26,12 @@ import org.apache.druid.data.input.Row; import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.dimension.DimensionSpec; +import org.apache.druid.segment.column.RowSignature; import org.joda.time.DateTime; import javax.annotation.Nullable; import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -45,7 +45,7 @@ import java.util.Map; * ResultRows may sometimes be created without space reserved for post-aggregators, in contexts where it is known * that post-aggregators will not be computed. * - * @see GroupByQuery#getResultRowOrder() + * @see GroupByQuery#getResultRowSignature() * @see GroupByQuery#getResultRowHasTimestamp() * @see GroupByQuery#getUniversalTimestamp() * @see GroupByQuery#getResultRowDimensionStart() @@ -158,11 +158,11 @@ public final class ResultRow */ public Map toMap(final GroupByQuery query) { - final List resultRowOrder = query.getResultRowOrder(); + final RowSignature signature = query.getResultRowSignature(); final Map map = new HashMap<>(); for (int i = query.getResultRowDimensionStart(); i < row.length; i++) { - final String columnName = resultRowOrder.get(i); + final String columnName = signature.getColumnName(i); map.put(columnName, row[i]); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java index 349d62f6f11..a4fd44068fa 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/epinephelinae/RowBasedGrouperHelper.java @@ -51,7 +51,6 @@ import org.apache.druid.query.filter.Filter; import org.apache.druid.query.filter.ValueMatcher; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryHelper; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.groupby.epinephelinae.Grouper.BufferComparator; import org.apache.druid.query.groupby.orderby.DefaultLimitSpec; @@ -365,7 +364,7 @@ public class RowBasedGrouperHelper @Override public Function columnFunction(final String columnName) { - final int columnIndex = query.getResultRowPositionLookup().getInt(columnName); + final int columnIndex = query.getResultRowSignature().indexOf(columnName); if (columnIndex < 0) { return row -> null; } else { @@ -377,7 +376,7 @@ public class RowBasedGrouperHelper return RowBasedColumnSelectorFactory.create( adapter, supplier::get, - GroupByQueryHelper.rowSignatureFor(query), + query.getResultRowSignature(), false ); } @@ -545,7 +544,7 @@ public class RowBasedGrouperHelper if (dimsToInclude != null) { for (String dimension : dimsToInclude) { - final int dimIndex = query.getResultRowPositionLookup().getInt(dimension); + final int dimIndex = query.getResultRowSignature().indexOf(dimension); if (dimIndex >= 0) { dimsToIncludeBitSet.set(dimIndex - resultRowDimensionStart); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/having/DimFilterHavingSpec.java b/processing/src/main/java/org/apache/druid/query/groupby/having/DimFilterHavingSpec.java index 9039b21a315..1e92e6cd2dd 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/having/DimFilterHavingSpec.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/having/DimFilterHavingSpec.java @@ -76,7 +76,7 @@ public class DimFilterHavingSpec implements HavingSpec this.finalizers = new Int2ObjectArrayMap<>(query.getAggregatorSpecs().size()); for (AggregatorFactory factory : query.getAggregatorSpecs()) { - final int i = query.getResultRowPositionLookup().getInt(factory.getName()); + final int i = query.getResultRowSignature().indexOf(factory.getName()); this.finalizers.put(i, factory::finalizeComputation); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/having/DimensionSelectorHavingSpec.java b/processing/src/main/java/org/apache/druid/query/groupby/having/DimensionSelectorHavingSpec.java index 80a9669994b..0e54e8d70f1 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/having/DimensionSelectorHavingSpec.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/having/DimensionSelectorHavingSpec.java @@ -74,7 +74,7 @@ public class DimensionSelectorHavingSpec implements HavingSpec @Override public void setQuery(GroupByQuery query) { - columnNumber = query.getResultRowPositionLookup().getInt(dimension); + columnNumber = query.getResultRowSignature().indexOf(dimension); } @Override diff --git a/processing/src/main/java/org/apache/druid/query/groupby/having/EqualToHavingSpec.java b/processing/src/main/java/org/apache/druid/query/groupby/having/EqualToHavingSpec.java index 0bd0d452334..8ac0957731f 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/having/EqualToHavingSpec.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/having/EqualToHavingSpec.java @@ -66,7 +66,7 @@ public class EqualToHavingSpec implements HavingSpec @Override public void setQuery(GroupByQuery query) { - columnNumber = query.getResultRowPositionLookup().getInt(aggregationName); + columnNumber = query.getResultRowSignature().indexOf(aggregationName); aggregators = HavingSpecUtil.computeAggregatorsMap(query.getAggregatorSpecs()); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/having/GreaterThanHavingSpec.java b/processing/src/main/java/org/apache/druid/query/groupby/having/GreaterThanHavingSpec.java index be141e9dfa0..b073e402abd 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/having/GreaterThanHavingSpec.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/having/GreaterThanHavingSpec.java @@ -66,7 +66,7 @@ public class GreaterThanHavingSpec implements HavingSpec @Override public void setQuery(GroupByQuery query) { - columnNumber = query.getResultRowPositionLookup().getInt(aggregationName); + columnNumber = query.getResultRowSignature().indexOf(aggregationName); aggregators = HavingSpecUtil.computeAggregatorsMap(query.getAggregatorSpecs()); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/having/LessThanHavingSpec.java b/processing/src/main/java/org/apache/druid/query/groupby/having/LessThanHavingSpec.java index 8bc3f97bbc3..d4b173d961f 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/having/LessThanHavingSpec.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/having/LessThanHavingSpec.java @@ -64,7 +64,7 @@ public class LessThanHavingSpec implements HavingSpec @Override public void setQuery(GroupByQuery query) { - columnNumber = query.getResultRowPositionLookup().getInt(aggregationName); + columnNumber = query.getResultRowSignature().indexOf(aggregationName); aggregators = HavingSpecUtil.computeAggregatorsMap(query.getAggregatorSpecs()); } diff --git a/processing/src/main/java/org/apache/druid/query/groupby/orderby/DefaultLimitSpec.java b/processing/src/main/java/org/apache/druid/query/groupby/orderby/DefaultLimitSpec.java index 13bdd276f78..20f3e8c42e6 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/orderby/DefaultLimitSpec.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/orderby/DefaultLimitSpec.java @@ -29,7 +29,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; -import it.unimi.dsi.fastutil.objects.Object2IntMap; import org.apache.druid.common.config.NullHandling; import org.apache.druid.data.input.Rows; import org.apache.druid.java.util.common.ISE; @@ -43,6 +42,7 @@ import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.ordering.StringComparator; import org.apache.druid.query.ordering.StringComparators; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import javax.annotation.Nullable; @@ -180,7 +180,7 @@ public class DefaultLimitSpec implements LimitSpec // Materialize the Comparator first for fast-fail error checking. final Ordering ordering = makeComparator( - query.getResultRowPositionLookup(), + query.getResultRowSignature(), query.getResultRowHasTimestamp(), query.getDimensions(), query.getAggregatorSpecs(), @@ -222,7 +222,7 @@ public class DefaultLimitSpec implements LimitSpec } private Ordering makeComparator( - Object2IntMap rowOrderLookup, + RowSignature rowSignature, boolean hasTimestamp, List dimensions, List aggs, @@ -265,7 +265,7 @@ public class DefaultLimitSpec implements LimitSpec String columnName = columnSpec.getDimension(); Ordering nextOrdering = null; - final int columnIndex = rowOrderLookup.applyAsInt(columnName); + final int columnIndex = rowSignature.indexOf(columnName); if (columnIndex >= 0) { if (postAggregatorsMap.containsKey(columnName)) { diff --git a/processing/src/main/java/org/apache/druid/query/groupby/strategy/GroupByStrategyV2.java b/processing/src/main/java/org/apache/druid/query/groupby/strategy/GroupByStrategyV2.java index 971194bee17..bc4dc1b464c 100644 --- a/processing/src/main/java/org/apache/druid/query/groupby/strategy/GroupByStrategyV2.java +++ b/processing/src/main/java/org/apache/druid/query/groupby/strategy/GroupByStrategyV2.java @@ -421,7 +421,7 @@ public class GroupByStrategyV2 implements GroupByStrategy // Insert dummy dimension so all subtotals queries have ResultRows with the same shape. // Use a field name that does not appear in the main query result, to assure the result will be null. String dimName = "_" + i; - while (query.getResultRowPositionLookup().getInt(dimName) >= 0) { + while (query.getResultRowSignature().indexOf(dimName) >= 0) { dimName = "_" + dimName; } newDimensions.add(DefaultDimensionSpec.of(dimName)); diff --git a/processing/src/main/java/org/apache/druid/query/lookup/LookupSegment.java b/processing/src/main/java/org/apache/druid/query/lookup/LookupSegment.java index 9e3387da8ac..6211f82b7a6 100644 --- a/processing/src/main/java/org/apache/druid/query/lookup/LookupSegment.java +++ b/processing/src/main/java/org/apache/druid/query/lookup/LookupSegment.java @@ -19,10 +19,10 @@ package org.apache.druid.query.lookup; -import com.google.common.collect.ImmutableMap; import org.apache.druid.java.util.common.ISE; import org.apache.druid.segment.RowAdapter; import org.apache.druid.segment.RowBasedSegment; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.join.lookup.LookupColumnSelectorFactory; import org.apache.druid.timeline.SegmentId; @@ -37,10 +37,11 @@ import java.util.function.ToLongFunction; */ public class LookupSegment extends RowBasedSegment> { - private static final Map ROW_SIGNATURE = ImmutableMap.of( - LookupColumnSelectorFactory.KEY_COLUMN, ValueType.STRING, - LookupColumnSelectorFactory.VALUE_COLUMN, ValueType.STRING - ); + private static final RowSignature ROW_SIGNATURE = + RowSignature.builder() + .add(LookupColumnSelectorFactory.KEY_COLUMN, ValueType.STRING) + .add(LookupColumnSelectorFactory.VALUE_COLUMN, ValueType.STRING) + .build(); public LookupSegment(final String lookupName, final LookupExtractorFactory lookupExtractorFactory) { diff --git a/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java index 7aa976e5547..cc6ae068f82 100644 --- a/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/scan/ScanQueryQueryToolChest.java @@ -37,9 +37,10 @@ import org.apache.druid.query.QueryPlus; import org.apache.druid.query.QueryRunner; import org.apache.druid.query.QueryToolChest; import org.apache.druid.query.aggregation.MetricManipulationFn; +import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; +import org.apache.druid.segment.column.ValueType; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -127,28 +128,44 @@ public class ScanQueryQueryToolChest extends QueryToolChest resultArrayFields(final ScanQuery query) + public RowSignature resultArraySignature(final ScanQuery query) { if (query.getColumns() == null || query.getColumns().isEmpty()) { // Note: if no specific list of columns is provided, then since we can't predict what columns will come back, we // unfortunately can't do array-based results. In this case, there is a major difference between standard and // array-based results: the standard results will detect and return _all_ columns, whereas the array-based results // will include none of them. - return Collections.emptyList(); - } else if (query.withNonNullLegacy(scanQueryConfig).isLegacy()) { - final List retVal = new ArrayList<>(); - retVal.add(ScanQueryEngine.LEGACY_TIMESTAMP_KEY); - retVal.addAll(query.getColumns()); - return retVal; + return RowSignature.empty(); } else { - return query.getColumns(); + final RowSignature.Builder builder = RowSignature.builder(); + + if (query.withNonNullLegacy(scanQueryConfig).isLegacy()) { + builder.add(ScanQueryEngine.LEGACY_TIMESTAMP_KEY, null); + } + + for (String columnName : query.getColumns()) { + // With the Scan query we only know the columnType for virtual columns. Let's report those, at least. + final ValueType columnType; + + final VirtualColumn virtualColumn = query.getVirtualColumns().getVirtualColumn(columnName); + if (virtualColumn != null) { + columnType = virtualColumn.capabilities(columnName).getType(); + } else { + // Unknown type. In the future, it would be nice to have a way to fill these in. + columnType = null; + } + + builder.add(columnName, columnType); + } + + return builder.build(); } } @Override public Sequence resultsAsArrays(final ScanQuery query, final Sequence resultSequence) { - final List fields = resultArrayFields(query); + final List fields = resultArraySignature(query).getColumnNames(); final Function mapper; switch (query.getResultFormat()) { diff --git a/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java index b2dceb8c360..e381ffe8681 100644 --- a/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChest.java @@ -50,10 +50,9 @@ import org.apache.druid.query.cache.CacheKeyBuilder; import org.apache.druid.query.context.ResponseContext; import org.apache.druid.segment.RowAdapters; import org.apache.druid.segment.RowBasedColumnSelectorFactory; -import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.joda.time.DateTime; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -219,7 +218,7 @@ public class TimeseriesQueryQueryToolChest extends QueryToolChest new MapBasedRow(null, null), - null, + RowSignature.empty(), false ) ); @@ -403,17 +402,13 @@ public class TimeseriesQueryQueryToolChest extends QueryToolChest resultArrayFields(TimeseriesQuery query) + public RowSignature resultArraySignature(TimeseriesQuery query) { - final List fields = new ArrayList<>( - 1 + query.getAggregatorSpecs().size() + query.getPostAggregatorSpecs().size() - ); - - fields.add(ColumnHolder.TIME_COLUMN_NAME); - query.getAggregatorSpecs().stream().map(AggregatorFactory::getName).forEach(fields::add); - query.getPostAggregatorSpecs().stream().map(PostAggregator::getName).forEach(fields::add); - - return fields; + return RowSignature.builder() + .addTimeColumn() + .addAggregators(query.getAggregatorSpecs()) + .addPostAggregators(query.getPostAggregatorSpecs()) + .build(); } @Override @@ -422,7 +417,7 @@ public class TimeseriesQueryQueryToolChest extends QueryToolChest> resultSequence ) { - final List fields = resultArrayFields(query); + final List fields = resultArraySignature(query).getColumnNames(); return Sequences.map( resultSequence, diff --git a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java index 2d6c5e851f6..18501259b81 100644 --- a/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java +++ b/processing/src/main/java/org/apache/druid/query/topn/TopNQueryQueryToolChest.java @@ -48,10 +48,10 @@ import org.apache.druid.query.context.ResponseContext; import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.segment.DimensionHandlerUtils; -import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.joda.time.DateTime; -import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -510,24 +510,20 @@ public class TopNQueryQueryToolChest extends QueryToolChest resultArrayFields(TopNQuery query) + public RowSignature resultArraySignature(TopNQuery query) { - final List fields = new ArrayList<>( - 2 + query.getAggregatorSpecs().size() + query.getPostAggregatorSpecs().size() - ); - - fields.add(ColumnHolder.TIME_COLUMN_NAME); - fields.add(query.getDimensionSpec().getOutputName()); - query.getAggregatorSpecs().stream().map(AggregatorFactory::getName).forEach(fields::add); - query.getPostAggregatorSpecs().stream().map(PostAggregator::getName).forEach(fields::add); - - return fields; + return RowSignature.builder() + .addTimeColumn() + .addDimensions(Collections.singletonList(query.getDimensionSpec())) + .addAggregators(query.getAggregatorSpecs()) + .addPostAggregators(query.getPostAggregatorSpecs()) + .build(); } @Override public Sequence resultsAsArrays(TopNQuery query, Sequence> resultSequence) { - final List fields = resultArrayFields(query); + final List fields = resultArraySignature(query).getColumnNames(); return resultSequence.flatMap( result -> { diff --git a/processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java b/processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java index 32936b64942..11250714a84 100644 --- a/processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java +++ b/processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java @@ -19,8 +19,8 @@ package org.apache.druid.segment; +import com.google.common.base.Preconditions; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableMap; import org.apache.druid.common.config.NullHandling; import org.apache.druid.data.input.Rows; import org.apache.druid.query.dimension.DimensionSpec; @@ -30,13 +30,13 @@ import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector; import org.apache.druid.segment.column.ColumnCapabilities; import org.apache.druid.segment.column.ColumnCapabilitiesImpl; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.data.IndexedInts; import org.apache.druid.segment.data.RangeIndexedInts; import javax.annotation.Nullable; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; @@ -49,19 +49,19 @@ public class RowBasedColumnSelectorFactory implements ColumnSelectorFactory { private final Supplier supplier; private final RowAdapter adapter; - private final Map rowSignature; + private final RowSignature rowSignature; private final boolean throwParseExceptions; private RowBasedColumnSelectorFactory( final Supplier supplier, final RowAdapter adapter, - @Nullable final Map rowSignature, + final RowSignature rowSignature, final boolean throwParseExceptions ) { this.supplier = supplier; this.adapter = adapter; - this.rowSignature = rowSignature != null ? rowSignature : ImmutableMap.of(); + this.rowSignature = Preconditions.checkNotNull(rowSignature, "rowSignature must be nonnull"); this.throwParseExceptions = throwParseExceptions; } @@ -71,15 +71,17 @@ public class RowBasedColumnSelectorFactory implements ColumnSelectorFactory * @param adapter adapter for these row objects * @param supplier supplier of row objects * @param signature will be used for reporting available columns and their capabilities. Note that the this - * factory will still allow creation of selectors on any field in the rows, even if it - * doesn't appear in "rowSignature". + * factory will still allow creation of selectors on any named field in the rows, even if + * it doesn't appear in "rowSignature". (It only needs to be accessible via + * {@link RowAdapter#columnFunction}.) As a result, you can achieve an untyped mode by + * passing in {@link RowSignature#empty()}. * @param throwParseExceptions whether numeric selectors should throw parse exceptions or use a default/null value * when their inputs are not actually numeric */ public static RowBasedColumnSelectorFactory create( final RowAdapter adapter, final Supplier supplier, - @Nullable final Map signature, + final RowSignature signature, final boolean throwParseExceptions ) { @@ -88,7 +90,7 @@ public class RowBasedColumnSelectorFactory implements ColumnSelectorFactory @Nullable static ColumnCapabilities getColumnCapabilities( - final Map rowSignature, + final RowSignature rowSignature, final String columnName ) { @@ -96,7 +98,7 @@ public class RowBasedColumnSelectorFactory implements ColumnSelectorFactory // TIME_COLUMN_NAME is handled specially; override the provided rowSignature. return new ColumnCapabilitiesImpl().setType(ValueType.LONG).setIsComplete(true); } else { - final ValueType valueType = rowSignature.get(columnName); + final ValueType valueType = rowSignature.getColumnType(columnName).orElse(null); // Do _not_ set isDictionaryEncoded or hasBitmapIndexes, because Row-based columns do not have those things. // Do set hasMultipleValues, because we might return multiple values. diff --git a/processing/src/main/java/org/apache/druid/segment/RowBasedCursor.java b/processing/src/main/java/org/apache/druid/segment/RowBasedCursor.java index a83759dac47..d4447a835ff 100644 --- a/processing/src/main/java/org/apache/druid/segment/RowBasedCursor.java +++ b/processing/src/main/java/org/apache/druid/segment/RowBasedCursor.java @@ -23,13 +23,12 @@ import org.apache.druid.java.util.common.granularity.Granularity; import org.apache.druid.query.BaseQuery; import org.apache.druid.query.filter.Filter; import org.apache.druid.query.filter.ValueMatcher; -import org.apache.druid.segment.column.ValueType; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.filter.BooleanValueMatcher; import org.joda.time.DateTime; import org.joda.time.Interval; import javax.annotation.Nullable; -import java.util.Map; import java.util.function.ToLongFunction; /** @@ -55,7 +54,7 @@ public class RowBasedCursor implements Cursor final VirtualColumns virtualColumns, final Granularity gran, final boolean descending, - final Map rowSignature + final RowSignature rowSignature ) { this.rowWalker = rowWalker; diff --git a/processing/src/main/java/org/apache/druid/segment/RowBasedSegment.java b/processing/src/main/java/org/apache/druid/segment/RowBasedSegment.java index 58e55e0ab55..512cbc22a0c 100644 --- a/processing/src/main/java/org/apache/druid/segment/RowBasedSegment.java +++ b/processing/src/main/java/org/apache/druid/segment/RowBasedSegment.java @@ -20,13 +20,12 @@ package org.apache.druid.segment; import com.google.common.base.Preconditions; -import org.apache.druid.segment.column.ValueType; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.timeline.SegmentId; import org.joda.time.Interval; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Map; /** * A {@link Segment} that is based on a stream of objects. @@ -57,7 +56,7 @@ public class RowBasedSegment extends AbstractSegment final SegmentId segmentId, final Iterable rowIterable, final RowAdapter rowAdapter, - final Map rowSignature + final RowSignature rowSignature ) { this.segmentId = Preconditions.checkNotNull(segmentId, "segmentId"); diff --git a/processing/src/main/java/org/apache/druid/segment/RowBasedStorageAdapter.java b/processing/src/main/java/org/apache/druid/segment/RowBasedStorageAdapter.java index 3901cebb280..b9f7b87f585 100644 --- a/processing/src/main/java/org/apache/druid/segment/RowBasedStorageAdapter.java +++ b/processing/src/main/java/org/apache/druid/segment/RowBasedStorageAdapter.java @@ -29,7 +29,7 @@ import org.apache.druid.java.util.common.guava.Sequences; import org.apache.druid.query.QueryMetrics; import org.apache.druid.query.filter.Filter; import org.apache.druid.segment.column.ColumnCapabilities; -import org.apache.druid.segment.column.ValueType; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.data.Indexed; import org.apache.druid.segment.data.ListIndexed; import org.joda.time.DateTime; @@ -39,7 +39,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; /** * A {@link StorageAdapter} that is based on a stream of objects. Generally created by a {@link RowBasedSegment}. @@ -50,12 +49,12 @@ public class RowBasedStorageAdapter implements StorageAdapter { private final Iterable rowIterable; private final RowAdapter rowAdapter; - private final Map rowSignature; + private final RowSignature rowSignature; RowBasedStorageAdapter( final Iterable rowIterable, final RowAdapter rowAdapter, - final Map rowSignature + final RowSignature rowSignature ) { this.rowIterable = Preconditions.checkNotNull(rowIterable, "rowIterable"); @@ -72,7 +71,7 @@ public class RowBasedStorageAdapter implements StorageAdapter @Override public Indexed getAvailableDimensions() { - return new ListIndexed<>(new ArrayList<>(rowSignature.keySet())); + return new ListIndexed<>(new ArrayList<>(rowSignature.getColumnNames())); } @Override diff --git a/processing/src/main/java/org/apache/druid/segment/column/RowSignature.java b/processing/src/main/java/org/apache/druid/segment/column/RowSignature.java new file mode 100644 index 00000000000..767f45fdc13 --- /dev/null +++ b/processing/src/main/java/org/apache/druid/segment/column/RowSignature.java @@ -0,0 +1,283 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.segment.column; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import org.apache.druid.common.guava.GuavaUtils; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.Pair; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.query.aggregation.AggregatorFactory; +import org.apache.druid.query.aggregation.PostAggregator; +import org.apache.druid.query.dimension.DimensionSpec; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * Type signature for a row in a Druid datasource or query result. Rows have an ordering and every + * column has a defined type. This is a little bit of a fiction in the Druid world (where rows do not _actually_ have + * well defined types) but we do impose types for the SQL layer. + * + * @see org.apache.druid.query.QueryToolChest#resultArraySignature which returns signatures for query results + * @see org.apache.druid.query.InlineDataSource#getRowSignature which returns signatures for inline datasources + */ +public class RowSignature +{ + private static final RowSignature EMPTY = new RowSignature(Collections.emptyList()); + + private final Map columnTypes = new HashMap<>(); + private final Object2IntMap columnPositions = new Object2IntOpenHashMap<>(); + private final List columnNames; + + private RowSignature(final List> columnTypeList) + { + this.columnPositions.defaultReturnValue(-1); + + final ImmutableList.Builder columnNamesBuilder = ImmutableList.builder(); + + for (int i = 0; i < columnTypeList.size(); i++) { + final Pair pair = columnTypeList.get(i); + final ValueType existingType = columnTypes.get(pair.lhs); + + if (columnTypes.containsKey(pair.lhs) && existingType != pair.rhs) { + // It's ok to add the same column twice as long as the type is consistent. + // Note: we need the containsKey because the existingType might be present, but null. + throw new IAE("Column[%s] has conflicting types [%s] and [%s]", pair.lhs, existingType, pair.rhs); + } + + columnTypes.put(pair.lhs, pair.rhs); + columnPositions.put(pair.lhs, i); + columnNamesBuilder.add(pair.lhs); + } + + this.columnNames = columnNamesBuilder.build(); + } + + public static Builder builder() + { + return new Builder(); + } + + public static RowSignature empty() + { + return EMPTY; + } + + /** + * Returns the name of the column at position {@code columnNumber}. + * + * @throws IndexOutOfBoundsException if columnNumber is not within our row length + */ + public String getColumnName(final int columnNumber) + { + return columnNames.get(columnNumber); + } + + /** + * Returns the type of the column named {@code columnName}, or empty if the type is unknown or the column does + * not exist. + */ + public Optional getColumnType(final String columnName) + { + return Optional.ofNullable(columnTypes.get(columnName)); + } + + /** + * Returns the type of the column at position {@code columnNumber}, or empty if the type is unknown. + * + * @throws IndexOutOfBoundsException if columnNumber is not within our row length + */ + public Optional getColumnType(final int columnNumber) + { + return Optional.ofNullable(columnTypes.get(getColumnName(columnNumber))); + } + + /** + * Returns a list of column names in the order they appear in this signature. + */ + public List getColumnNames() + { + return columnNames; + } + + /** + * Returns the number of columns in this signature. + */ + public int size() + { + return columnNames.size(); + } + + /** + * Returns whether this signature contains a named column. + */ + public boolean contains(final String columnName) + { + return columnPositions.containsKey(columnName); + } + + /** + * Returns the first position of {@code columnName} in this row signature, or -1 if it does not appear. + * + * Note: the same column name may appear more than once in a signature; if it does, this method will return the + * first appearance. + */ + public int indexOf(final String columnName) + { + return columnPositions.applyAsInt(columnName); + } + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RowSignature that = (RowSignature) o; + return columnTypes.equals(that.columnTypes) && + columnNames.equals(that.columnNames); + } + + @Override + public int hashCode() + { + return Objects.hash(columnTypes, columnNames); + } + + @Override + public String toString() + { + final StringBuilder s = new StringBuilder("{"); + for (int i = 0; i < columnNames.size(); i++) { + if (i > 0) { + s.append(", "); + } + final String columnName = columnNames.get(i); + s.append(columnName).append(":").append(columnTypes.get(columnName)); + } + return s.append("}").toString(); + } + + public static class Builder + { + private final List> columnTypeList; + + private Builder() + { + this.columnTypeList = new ArrayList<>(); + } + + /** + * Add a column to this signature. + * + * @param columnName name, must be nonnull + * @param columnType type, may be null if unknown + */ + public Builder add(final String columnName, @Nullable final ValueType columnType) + { + // Name must be nonnull, but type can be null (if the type is unknown) + Preconditions.checkNotNull(columnName, "'columnName' must be nonnull"); + columnTypeList.add(Pair.of(columnName, columnType)); + return this; + } + + public Builder addAll(final RowSignature other) + { + for (String columnName : other.getColumnNames()) { + add(columnName, other.getColumnType(columnName).orElse(null)); + } + + return this; + } + + public Builder addTimeColumn() + { + return add(ColumnHolder.TIME_COLUMN_NAME, ValueType.LONG); + } + + public Builder addDimensions(final List dimensions) + { + for (final DimensionSpec dimension : dimensions) { + add(dimension.getOutputName(), dimension.getOutputType()); + } + + return this; + } + + public Builder addAggregators(final List aggregators) + { + for (final AggregatorFactory aggregator : aggregators) { + final ValueType type = GuavaUtils.getEnumIfPresent( + ValueType.class, + StringUtils.toUpperCase(aggregator.getTypeName()) + ); + + // Use null instead of COMPLEX for nonnumeric types, since in that case, the type depends on whether or not + // the aggregator is finalized, and we don't know (a) if it will be finalized, or even (b) what the type would + // be if it were finalized. So null (i.e. unknown) is the proper thing to do. + // + // Another note: technically, we don't know what the finalized type will be even if the type here is numeric, + // but we're assuming that it doesn't change upon finalization. All builtin aggregators work this way. + + if (type != null && type.isNumeric()) { + add(aggregator.getName(), type); + } else { + add(aggregator.getName(), null); + } + } + + return this; + } + + public Builder addPostAggregators(final List postAggregators) + { + for (final PostAggregator postAggregator : postAggregators) { + // PostAggregator#getName is marked nullable, but we require column names for everything. + final String name = Preconditions.checkNotNull( + postAggregator.getName(), + "postAggregators must have nonnull names" + ); + + // PostAggregators don't have known types; use null for the type. + add(name, null); + } + + return this; + } + + public RowSignature build() + { + return new RowSignature(columnTypeList); + } + } +} diff --git a/processing/src/main/java/org/apache/druid/segment/column/ValueType.java b/processing/src/main/java/org/apache/druid/segment/column/ValueType.java index 97885e9e378..4bdbcfb87fe 100644 --- a/processing/src/main/java/org/apache/druid/segment/column/ValueType.java +++ b/processing/src/main/java/org/apache/druid/segment/column/ValueType.java @@ -121,7 +121,8 @@ public enum ValueType } @JsonCreator - public static ValueType fromString(String name) + @Nullable + public static ValueType fromString(@Nullable String name) { if (name == null) { return null; diff --git a/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java b/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java index f7cdd3c1524..82b92766d5e 100644 --- a/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java +++ b/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndex.java @@ -69,6 +69,7 @@ import org.apache.druid.segment.VirtualColumns; import org.apache.druid.segment.column.ColumnCapabilities; import org.apache.druid.segment.column.ColumnCapabilitiesImpl; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.serde.ComplexMetricExtractor; import org.apache.druid.segment.serde.ComplexMetricSerde; @@ -134,7 +135,7 @@ public abstract class IncrementalIndex extends AbstractIndex imp final RowBasedColumnSelectorFactory baseSelectorFactory = RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), in::get, - null, + RowSignature.empty(), true ); diff --git a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTable.java b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTable.java index dfd64b1e4ea..cbc858112f3 100644 --- a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTable.java +++ b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTable.java @@ -20,11 +20,9 @@ package org.apache.druid.segment.join.table; import it.unimi.dsi.fastutil.ints.IntList; -import org.apache.druid.segment.column.ValueType; +import org.apache.druid.segment.column.RowSignature; import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -40,15 +38,10 @@ public interface IndexedTable Set keyColumns(); /** - * Returns all columns of this table, including the key and non-key columns. + * Returns the signature of this table, which includes all key columns (as well as other columns that can be + * selected, but are not keys). */ - List allColumns(); - - /** - * Returns the signature of this table: a map where each key is a column from {@link #allColumns()} and each value - * is a type code. - */ - Map rowSignature(); + RowSignature rowSignature(); /** * Returns the number of rows in this table. It must not change over time, since it is used for things like algorithm @@ -58,13 +51,13 @@ public interface IndexedTable /** * Returns the index for a particular column. The provided column number must be that column's position in - * {@link #allColumns()}. + * {@link #rowSignature()}. */ Index columnIndex(int column); /** * Returns a reader for a particular column. The provided column number must be that column's position in - * {@link #allColumns()}. + * {@link #rowSignature()}. */ Reader columnReader(int column); diff --git a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableColumnSelectorFactory.java b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableColumnSelectorFactory.java index e5d72e2e8c6..2b0b5c79e3c 100644 --- a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableColumnSelectorFactory.java +++ b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableColumnSelectorFactory.java @@ -46,7 +46,7 @@ public class IndexedTableColumnSelectorFactory implements ColumnSelectorFactory @Nullable static ColumnCapabilities columnCapabilities(final IndexedTable table, final String columnName) { - final ValueType valueType = table.rowSignature().get(columnName); + final ValueType valueType = table.rowSignature().getColumnType(columnName).orElse(null); if (valueType != null) { final ColumnCapabilitiesImpl capabilities = new ColumnCapabilitiesImpl().setType(valueType); @@ -66,7 +66,7 @@ public class IndexedTableColumnSelectorFactory implements ColumnSelectorFactory @Override public DimensionSelector makeDimensionSelector(final DimensionSpec dimensionSpec) { - final int columnNumber = table.allColumns().indexOf(dimensionSpec.getDimension()); + final int columnNumber = table.rowSignature().indexOf(dimensionSpec.getDimension()); if (columnNumber < 0) { return dimensionSpec.decorate(DimensionSelector.constant(null, dimensionSpec.getExtractionFn())); @@ -86,7 +86,7 @@ public class IndexedTableColumnSelectorFactory implements ColumnSelectorFactory @Override public ColumnValueSelector makeColumnValueSelector(final String columnName) { - final int columnNumber = table.allColumns().indexOf(columnName); + final int columnNumber = table.rowSignature().indexOf(columnName); if (columnNumber < 0) { return NilColumnValueSelector.instance(); diff --git a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcher.java b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcher.java index 5313bac26f3..22887b54d9f 100644 --- a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcher.java +++ b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcher.java @@ -30,6 +30,7 @@ import it.unimi.dsi.fastutil.ints.IntRBTreeSet; import it.unimi.dsi.fastutil.ints.IntSet; import org.apache.druid.common.config.NullHandling; import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.ISE; import org.apache.druid.segment.BaseDoubleColumnValueSelector; import org.apache.druid.segment.BaseFloatColumnValueSelector; import org.apache.druid.segment.BaseLongColumnValueSelector; @@ -122,8 +123,12 @@ public class IndexedTableJoinMatcher implements JoinMatcher throw new IAE("Cannot build hash-join matcher on non-key-based condition: %s", condition); } - final int keyColumnNumber = table.allColumns().indexOf(condition.getRightColumn()); - final ValueType keyColumnType = table.rowSignature().get(condition.getRightColumn()); + final int keyColumnNumber = table.rowSignature().indexOf(condition.getRightColumn()); + + final ValueType keyColumnType = + table.rowSignature().getColumnType(condition.getRightColumn()) + .orElseThrow(() -> new ISE("Encountered null type for column[%s]", condition.getRightColumn())); + final IndexedTable.Index index = table.columnIndex(keyColumnNumber); return ColumnProcessors.makeProcessor( diff --git a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinable.java b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinable.java index 3e2084dc0f6..1eb01fe4e1e 100644 --- a/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinable.java +++ b/processing/src/main/java/org/apache/druid/segment/join/table/IndexedTableJoinable.java @@ -44,13 +44,13 @@ public class IndexedTableJoinable implements Joinable @Override public List getAvailableColumns() { - return table.allColumns(); + return table.rowSignature().getColumnNames(); } @Override public int getCardinality(String columnName) { - if (table.allColumns().contains(columnName)) { + if (table.rowSignature().contains(columnName)) { return table.numRows(); } else { // NullDimensionSelector has cardinality = 1 (one null, nothing else). @@ -87,8 +87,8 @@ public class IndexedTableJoinable implements Joinable String retrievalColumnName ) { - int filterColumnPosition = table.allColumns().indexOf(searchColumnName); - int correlatedColumnPosition = table.allColumns().indexOf(retrievalColumnName); + int filterColumnPosition = table.rowSignature().indexOf(searchColumnName); + int correlatedColumnPosition = table.rowSignature().indexOf(retrievalColumnName); if (filterColumnPosition < 0 || correlatedColumnPosition < 0) { return ImmutableSet.of(); diff --git a/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexedTable.java b/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexedTable.java index 37e9cb59e8a..5d7e905512a 100644 --- a/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexedTable.java +++ b/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexedTable.java @@ -19,6 +19,7 @@ package org.apache.druid.segment.join.table; +import com.google.common.collect.ImmutableSet; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntLists; @@ -26,6 +27,7 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.ISE; import org.apache.druid.segment.DimensionHandlerUtils; import org.apache.druid.segment.RowAdapter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import java.util.ArrayList; @@ -45,48 +47,46 @@ public class RowBasedIndexedTable implements IndexedTable { private final List table; private final List> index; - private final Map rowSignature; - private final List columns; - private final List columnTypes; + private final RowSignature rowSignature; private final List> columnFunctions; private final Set keyColumns; public RowBasedIndexedTable( final List table, final RowAdapter rowAdapter, - final Map rowSignature, + final RowSignature rowSignature, final Set keyColumns ) { this.table = table; this.rowSignature = rowSignature; - this.columns = rowSignature.keySet().stream().sorted().collect(Collectors.toList()); - this.columnTypes = new ArrayList<>(columns.size()); - this.columnFunctions = columns.stream().map(rowAdapter::columnFunction).collect(Collectors.toList()); + this.columnFunctions = + rowSignature.getColumnNames().stream().map(rowAdapter::columnFunction).collect(Collectors.toList()); this.keyColumns = keyColumns; if (new HashSet<>(keyColumns).size() != keyColumns.size()) { throw new ISE("keyColumns[%s] must not contain duplicates", keyColumns); } - if (!rowSignature.keySet().containsAll(keyColumns)) { + if (!ImmutableSet.copyOf(rowSignature.getColumnNames()).containsAll(keyColumns)) { throw new ISE( "keyColumns[%s] must all be contained in rowSignature[%s]", String.join(", ", keyColumns), - String.join(", ", rowSignature.keySet()) + rowSignature ); } - index = new ArrayList<>(columns.size()); + index = new ArrayList<>(rowSignature.size()); - for (int i = 0; i < columns.size(); i++) { - final String column = columns.get(i); + for (int i = 0; i < rowSignature.size(); i++) { + final String column = rowSignature.getColumnName(i); final Map m; - final ValueType columnType = rowSignature.get(column); - - columnTypes.add(columnType); if (keyColumns.contains(column)) { + final ValueType columnType = + rowSignature.getColumnType(column) + .orElseThrow(() -> new ISE("Key column[%s] must have nonnull type", column)); + final Function columnFunction = columnFunctions.get(i); m = new HashMap<>(); @@ -114,13 +114,7 @@ public class RowBasedIndexedTable implements IndexedTable } @Override - public List allColumns() - { - return columns; - } - - @Override - public Map rowSignature() + public RowSignature rowSignature() { return rowSignature; } @@ -134,7 +128,9 @@ public class RowBasedIndexedTable implements IndexedTable throw new IAE("Column[%d] is not a key column", column); } - final ValueType columnType = columnTypes.get(column); + final ValueType columnType = + rowSignature.getColumnType(column) + .orElseThrow(() -> new ISE("Key column[%s] must have nonnull type", column)); return key -> { final Object convertedKey = DimensionHandlerUtils.convertObjectToType(key, columnType, false); diff --git a/processing/src/main/java/org/apache/druid/segment/transform/Transformer.java b/processing/src/main/java/org/apache/druid/segment/transform/Transformer.java index 74ebdd06508..48b0421c7b8 100644 --- a/processing/src/main/java/org/apache/druid/segment/transform/Transformer.java +++ b/processing/src/main/java/org/apache/druid/segment/transform/Transformer.java @@ -28,6 +28,7 @@ import org.apache.druid.query.filter.ValueMatcher; import org.apache.druid.segment.RowAdapters; import org.apache.druid.segment.RowBasedColumnSelectorFactory; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.joda.time.DateTime; import javax.annotation.Nullable; @@ -58,7 +59,7 @@ public class Transformer RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), rowSupplierForValueMatcher::get, - null, + RowSignature.empty(), false ) ); diff --git a/processing/src/test/java/org/apache/druid/query/InlineDataSourceTest.java b/processing/src/test/java/org/apache/druid/query/InlineDataSourceTest.java index 70d1f37eca1..3cae4062193 100644 --- a/processing/src/test/java/org/apache/druid/query/InlineDataSourceTest.java +++ b/processing/src/test/java/org/apache/druid/query/InlineDataSourceTest.java @@ -28,6 +28,7 @@ import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.segment.RowAdapter; import org.apache.druid.segment.TestHelper; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.junit.Assert; import org.junit.Rule; @@ -114,12 +115,12 @@ public class InlineDataSourceTest public void test_getRowSignature() { Assert.assertEquals( - ImmutableMap.of( - ColumnHolder.TIME_COLUMN_NAME, ValueType.LONG, - "str", ValueType.STRING, - "double", ValueType.DOUBLE, - "complex", ValueType.COMPLEX - ), + RowSignature.builder() + .add(ColumnHolder.TIME_COLUMN_NAME, ValueType.LONG) + .add("str", ValueType.STRING) + .add("double", ValueType.DOUBLE) + .add("complex", ValueType.COMPLEX) + .build(), listDataSource.getRowSignature() ); } diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChestTest.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChestTest.java index bdb771c0127..f3e0befbe9c 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChestTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChestTest.java @@ -64,6 +64,7 @@ import org.apache.druid.query.groupby.orderby.DefaultLimitSpec; import org.apache.druid.query.groupby.orderby.OrderByColumnSpec; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.TestHelper; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.junit.Assert; @@ -666,7 +667,7 @@ public class GroupByQueryQueryToolChestTest } @Test - public void testResultArrayFieldsAllGran() + public void testResultArraySignatureAllGran() { final GroupByQuery query = new GroupByQuery.Builder() .setDataSource(QueryRunnerTestHelper.DATA_SOURCE) @@ -678,13 +679,19 @@ public class GroupByQueryQueryToolChestTest .build(); Assert.assertEquals( - ImmutableList.of("dim", "rows", "index", "uniques", "const"), - new GroupByQueryQueryToolChest(null, null).resultArrayFields(query) + RowSignature.builder() + .add("dim", ValueType.STRING) + .add("rows", ValueType.LONG) + .add("index", ValueType.DOUBLE) + .add("uniques", null) + .add("const", null) + .build(), + new GroupByQueryQueryToolChest(null, null).resultArraySignature(query) ); } @Test - public void testResultArrayFieldsDayGran() + public void testResultArraySignatureDayGran() { final GroupByQuery query = new GroupByQuery.Builder() .setDataSource(QueryRunnerTestHelper.DATA_SOURCE) @@ -696,8 +703,15 @@ public class GroupByQueryQueryToolChestTest .build(); Assert.assertEquals( - ImmutableList.of("__time", "dim", "rows", "index", "uniques", "const"), - new GroupByQueryQueryToolChest(null, null).resultArrayFields(query) + RowSignature.builder() + .addTimeColumn() + .add("dim", ValueType.STRING) + .add("rows", ValueType.LONG) + .add("index", ValueType.DOUBLE) + .add("uniques", null) + .add("const", null) + .build(), + new GroupByQueryQueryToolChest(null, null).resultArraySignature(query) ); } diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java index 60327ba3e3f..1b8519d68b4 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTest.java @@ -3300,8 +3300,8 @@ public class GroupByQueryRunnerTest extends InitializedNullHandlingTest makeRow(baseQuery, "2011-04-01", "alias", "travel", "rows", 2L, "idx", 243L) ); - final int idxPosition = baseQuery.getResultRowPositionLookup().getInt("idx"); - final int rowsPosition = baseQuery.getResultRowPositionLookup().getInt("rows"); + final int idxPosition = baseQuery.getResultRowSignature().indexOf("idx"); + final int rowsPosition = baseQuery.getResultRowSignature().indexOf("rows"); Comparator idxComparator = Comparator.comparing(row -> ((Number) row.get(idxPosition)).floatValue()); Comparator rowsComparator = Comparator.comparing(row -> ((Number) row.get(rowsPosition)).floatValue()); @@ -5356,7 +5356,7 @@ public class GroupByQueryRunnerTest extends InitializedNullHandlingTest public boolean eval(ResultRow row) { final String field = "idx_subpostagg"; - final int p = query.getResultRowPositionLookup().getInt(field); + final int p = query.getResultRowSignature().indexOf(field); return (Rows.objectToNumber(field, row.get(p), true).floatValue() < 3800); } } @@ -5650,7 +5650,7 @@ public class GroupByQueryRunnerTest extends InitializedNullHandlingTest public boolean eval(ResultRow row) { final String field = "idx_subpostagg"; - final int p = query.getResultRowPositionLookup().getInt(field); + final int p = query.getResultRowSignature().indexOf(field); return (Rows.objectToNumber(field, row.get(p), true).floatValue() < 3800); } } diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java index dd152533454..6356a1535a8 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java @@ -74,7 +74,7 @@ public class GroupByQueryRunnerTestHelper } for (int i = 0; i < vals.length; i += 2) { - final int position = query.getResultRowPositionLookup().getInt(vals[i].toString()); + final int position = query.getResultRowSignature().indexOf(vals[i].toString()); row.set(position, vals[i + 1]); } @@ -100,7 +100,7 @@ public class GroupByQueryRunnerTestHelper ResultRow row = ResultRow.create(query.getResultRowSizeWithPostAggregators()); for (int i = 0; i < columnNames.length; i++) { if (i != timeIndex) { - final int position = query.getResultRowPositionLookup().getInt(columnNames[i]); + final int position = query.getResultRowSignature().indexOf(columnNames[i]); row.set(position, value[i]); } else if (query.getResultRowHasTimestamp()) { row.set(0, new DateTime(value[i], ISOChronology.getInstanceUTC()).getMillis()); diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java index 2745802a790..bd6938ec0b8 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryTest.java @@ -136,8 +136,7 @@ public class GroupByQueryTest .withIgnoredFields( "applyLimitPushDown", "postProcessingFn", - "resultRowOrder", - "resultRowPositionLookup", + "resultRowSignature", "universalTimestamp" ) .verify(); diff --git a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryQueryToolChestTest.java b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryQueryToolChestTest.java index d0fe752bb01..bdd9b01838c 100644 --- a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryQueryToolChestTest.java +++ b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryQueryToolChestTest.java @@ -28,6 +28,7 @@ import org.apache.druid.query.DefaultGenericQueryMetricsFactory; import org.apache.druid.query.Druids; import org.apache.druid.query.QueryToolChestTestHelper; import org.apache.druid.query.spec.MultipleIntervalSegmentSpec; +import org.apache.druid.segment.column.RowSignature; import org.junit.Assert; import org.junit.Test; @@ -51,7 +52,7 @@ public class ScanQueryQueryToolChestTest ); @Test - public void test_resultArrayFields_columnsNotSpecified() + public void test_resultArraySignature_columnsNotSpecified() { final ScanQuery scanQuery = Druids.newScanQueryBuilder() @@ -59,11 +60,11 @@ public class ScanQueryQueryToolChestTest .intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2000/3000")))) .build(); - Assert.assertEquals(ImmutableList.of(), toolChest.resultArrayFields(scanQuery)); + Assert.assertEquals(RowSignature.empty(), toolChest.resultArraySignature(scanQuery)); } @Test - public void test_resultArrayFields_columnsNotSpecifiedLegacyMode() + public void test_resultArraySignature_columnsNotSpecifiedLegacyMode() { final ScanQuery scanQuery = Druids.newScanQueryBuilder() @@ -72,11 +73,11 @@ public class ScanQueryQueryToolChestTest .legacy(true) .build(); - Assert.assertEquals(ImmutableList.of(), toolChest.resultArrayFields(scanQuery)); + Assert.assertEquals(RowSignature.empty(), toolChest.resultArraySignature(scanQuery)); } @Test - public void test_resultArrayFields_columnsSpecified() + public void test_resultArraySignature_columnsSpecified() { final ScanQuery scanQuery = Druids.newScanQueryBuilder() @@ -85,11 +86,14 @@ public class ScanQueryQueryToolChestTest .columns("foo", "bar") .build(); - Assert.assertEquals(ImmutableList.of("foo", "bar"), toolChest.resultArrayFields(scanQuery)); + Assert.assertEquals( + RowSignature.builder().add("foo", null).add("bar", null).build(), + toolChest.resultArraySignature(scanQuery) + ); } @Test - public void test_resultArrayFields_columnsSpecifiedLegacyMode() + public void test_resultArraySignature_columnsSpecifiedLegacyMode() { final ScanQuery scanQuery = Druids.newScanQueryBuilder() @@ -99,7 +103,10 @@ public class ScanQueryQueryToolChestTest .legacy(true) .build(); - Assert.assertEquals(ImmutableList.of("timestamp", "foo", "bar"), toolChest.resultArrayFields(scanQuery)); + Assert.assertEquals( + RowSignature.builder().add("timestamp", null).add("foo", null).add("bar", null).build(), + toolChest.resultArraySignature(scanQuery) + ); } @Test diff --git a/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java b/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java index 58547979234..3f6e59b7f49 100644 --- a/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java +++ b/processing/src/test/java/org/apache/druid/query/timeseries/TimeseriesQueryQueryToolChestTest.java @@ -22,6 +22,7 @@ package org.apache.druid.query.timeseries; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import org.apache.druid.common.config.NullHandling; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; @@ -42,7 +43,10 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.spec.MultipleIntervalSegmentSpec; import org.apache.druid.segment.TestHelper; import org.apache.druid.segment.VirtualColumns; +import org.apache.druid.segment.column.RowSignature; +import org.apache.druid.segment.column.ValueType; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -54,6 +58,12 @@ public class TimeseriesQueryQueryToolChestTest { private static final TimeseriesQueryQueryToolChest TOOL_CHEST = new TimeseriesQueryQueryToolChest(null); + @BeforeClass + public static void setUpClass() + { + NullHandling.initializeForTests(); + } + @Parameterized.Parameters(name = "descending={0}") public static Iterable constructorFeeder() { @@ -354,7 +364,7 @@ public class TimeseriesQueryQueryToolChestTest } @Test - public void testResultArrayFields() + public void testResultArraySignature() { final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder() @@ -367,8 +377,14 @@ public class TimeseriesQueryQueryToolChestTest .build(); Assert.assertEquals( - ImmutableList.of("__time", "rows", "index", "uniques", "const"), - TOOL_CHEST.resultArrayFields(query) + RowSignature.builder() + .addTimeColumn() + .add("rows", ValueType.LONG) + .add("index", ValueType.DOUBLE) + .add("uniques", null) + .add("const", null) + .build(), + TOOL_CHEST.resultArraySignature(query) ); } diff --git a/processing/src/test/java/org/apache/druid/query/topn/TopNQueryQueryToolChestTest.java b/processing/src/test/java/org/apache/druid/query/topn/TopNQueryQueryToolChestTest.java index 760d1c26853..8246f97b0e2 100644 --- a/processing/src/test/java/org/apache/druid/query/topn/TopNQueryQueryToolChestTest.java +++ b/processing/src/test/java/org/apache/druid/query/topn/TopNQueryQueryToolChestTest.java @@ -61,6 +61,7 @@ import org.apache.druid.segment.IncrementalIndexSegment; import org.apache.druid.segment.TestHelper; import org.apache.druid.segment.TestIndex; import org.apache.druid.segment.VirtualColumns; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.testing.InitializedNullHandlingTest; import org.apache.druid.timeline.SegmentId; @@ -298,7 +299,7 @@ public class TopNQueryQueryToolChestTest extends InitializedNullHandlingTest } @Test - public void testResultArrayFields() + public void testResultArraySignature() { final TopNQuery query = new TopNQueryBuilder() .dataSource(QueryRunnerTestHelper.DATA_SOURCE) @@ -312,8 +313,15 @@ public class TopNQueryQueryToolChestTest extends InitializedNullHandlingTest .build(); Assert.assertEquals( - ImmutableList.of("__time", "dim", "rows", "index", "uniques", "const"), - new TopNQueryQueryToolChest(null, null).resultArrayFields(query) + RowSignature.builder() + .addTimeColumn() + .add("dim", ValueType.STRING) + .add("rows", ValueType.LONG) + .add("index", ValueType.DOUBLE) + .add("uniques", null) + .add("const", null) + .build(), + new TopNQueryQueryToolChest(null, null).resultArraySignature(query) ); } diff --git a/processing/src/test/java/org/apache/druid/segment/IndexBuilder.java b/processing/src/test/java/org/apache/druid/segment/IndexBuilder.java index 629c9fcbc73..5813f6d298e 100644 --- a/processing/src/test/java/org/apache/druid/segment/IndexBuilder.java +++ b/processing/src/test/java/org/apache/druid/segment/IndexBuilder.java @@ -20,7 +20,6 @@ package org.apache.druid.segment; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import org.apache.druid.data.input.InputRow; @@ -29,7 +28,7 @@ import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.CountAggregatorFactory; import org.apache.druid.segment.column.ColumnCapabilities; import org.apache.druid.segment.column.ColumnConfig; -import org.apache.druid.segment.column.ValueType; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.incremental.IncrementalIndex; import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.incremental.IndexSizeExceededException; @@ -42,10 +41,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.Collectors; /** * Helps tests make segments. @@ -198,7 +195,7 @@ public class IndexBuilder SegmentId.dummy("IndexBuilder"), rows, RowAdapters.standardRow(), - ImmutableMap.of() + RowSignature.empty() ); } @@ -206,22 +203,17 @@ public class IndexBuilder { // Determine row signature by building an mmapped index first. try (final QueryableIndex index = buildMMappedIndex()) { - final Map rowSignature = - index.getColumnNames().stream().collect( - Collectors.toMap( - column -> column, - column -> { - final ColumnCapabilities capabilities = index.getColumnHolder(column).getCapabilities(); - return capabilities.getType(); - } - ) - ); + final RowSignature.Builder rowSignatureBuilder = RowSignature.builder(); + for (final String columnName : index.getColumnNames()) { + final ColumnCapabilities capabilities = index.getColumnHolder(columnName).getCapabilities(); + rowSignatureBuilder.add(columnName, capabilities.getType()); + } return new RowBasedSegment<>( SegmentId.dummy("IndexBuilder"), rows, RowAdapters.standardRow(), - rowSignature + rowSignatureBuilder.build() ); } } diff --git a/processing/src/test/java/org/apache/druid/segment/RowBasedStorageAdapterTest.java b/processing/src/test/java/org/apache/druid/segment/RowBasedStorageAdapterTest.java index 07086c42f4b..ecd2dc40c16 100644 --- a/processing/src/test/java/org/apache/druid/segment/RowBasedStorageAdapterTest.java +++ b/processing/src/test/java/org/apache/druid/segment/RowBasedStorageAdapterTest.java @@ -20,7 +20,6 @@ package org.apache.druid.segment; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.druid.common.config.NullHandling; import org.apache.druid.common.guava.GuavaUtils; @@ -34,6 +33,7 @@ import org.apache.druid.math.expr.ExprMacroTable; import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.segment.column.ColumnCapabilities; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.joda.time.Duration; @@ -48,7 +48,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.ToLongFunction; @@ -56,14 +55,14 @@ import java.util.stream.Collectors; public class RowBasedStorageAdapterTest { - private static final Map ROW_SIGNATURE = - ImmutableMap.builder() - .put(ValueType.FLOAT.name(), ValueType.FLOAT) - .put(ValueType.DOUBLE.name(), ValueType.DOUBLE) - .put(ValueType.LONG.name(), ValueType.LONG) - .put(ValueType.STRING.name(), ValueType.STRING) - .put(ValueType.COMPLEX.name(), ValueType.COMPLEX) - .build(); + private static final RowSignature ROW_SIGNATURE = + RowSignature.builder() + .add(ValueType.FLOAT.name(), ValueType.FLOAT) + .add(ValueType.DOUBLE.name(), ValueType.DOUBLE) + .add(ValueType.LONG.name(), ValueType.LONG) + .add(ValueType.STRING.name(), ValueType.STRING) + .add(ValueType.COMPLEX.name(), ValueType.COMPLEX) + .build(); private static final List>> READ_STRING = ImmutableList.of( @@ -101,7 +100,7 @@ public class RowBasedStorageAdapterTest // Read all the types as all the other types. - for (final String valueTypeName : ROW_SIGNATURE.keySet()) { + for (final String valueTypeName : ROW_SIGNATURE.getColumnNames()) { PROCESSORS.put( StringUtils.format("%s-float", StringUtils.toLowerCase(valueTypeName)), cursor -> { @@ -223,7 +222,7 @@ public class RowBasedStorageAdapterTest // Sort them for comparison purposes. Assert.assertEquals( - ROW_SIGNATURE.keySet().stream().sorted().collect(Collectors.toList()), + ROW_SIGNATURE.getColumnNames().stream().sorted().collect(Collectors.toList()), Lists.newArrayList(adapter.getAvailableDimensions()).stream().sorted().collect(Collectors.toList()) ); } @@ -245,7 +244,7 @@ public class RowBasedStorageAdapterTest final RowBasedStorageAdapter adapter = createIntAdapter(0, 1, 2); // Row based adapters don't know cardinality (they don't walk their Iterables until makeCursors is called). - for (String column : ROW_SIGNATURE.keySet()) { + for (String column : ROW_SIGNATURE.getColumnNames()) { Assert.assertEquals(Integer.MAX_VALUE, adapter.getDimensionCardinality(column)); } } @@ -286,7 +285,7 @@ public class RowBasedStorageAdapterTest // Row based adapters don't know min/max values, so they always return null. // Test both known and unknown columns. final List columns = - ImmutableList.builder().addAll(ROW_SIGNATURE.keySet()).add("unknown", "__time").build(); + ImmutableList.builder().addAll(ROW_SIGNATURE.getColumnNames()).add("unknown", "__time").build(); for (String column : columns) { Assert.assertNull(column, adapter.getMinValue(column)); @@ -301,7 +300,7 @@ public class RowBasedStorageAdapterTest // Row based adapters don't know min/max values, so they always return null. // Test both known and unknown columns. final List columns = - ImmutableList.builder().addAll(ROW_SIGNATURE.keySet()).add("unknown", "__time").build(); + ImmutableList.builder().addAll(ROW_SIGNATURE.getColumnNames()).add("unknown", "__time").build(); for (String column : columns) { Assert.assertNull(column, adapter.getMaxValue(column)); @@ -314,7 +313,7 @@ public class RowBasedStorageAdapterTest final RowBasedStorageAdapter adapter = createIntAdapter(0, 1, 2); // Row based adapters don't know cardinality (they don't walk their Iterables until makeCursors is called). - for (String column : ROW_SIGNATURE.keySet()) { + for (String column : ROW_SIGNATURE.getColumnNames()) { Assert.assertEquals(Integer.MAX_VALUE, adapter.getDimensionCardinality(column)); } } @@ -393,7 +392,7 @@ public class RowBasedStorageAdapterTest { final RowBasedStorageAdapter adapter = createIntAdapter(0, 1, 2); - for (String columnName : ROW_SIGNATURE.keySet()) { + for (String columnName : ROW_SIGNATURE.getColumnNames()) { Assert.assertEquals(columnName, ValueType.valueOf(columnName).name(), adapter.getColumnTypeName(columnName)); } } diff --git a/processing/src/test/java/org/apache/druid/segment/filter/BaseFilterTest.java b/processing/src/test/java/org/apache/druid/segment/filter/BaseFilterTest.java index 190ab06329b..8a704d265ac 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/BaseFilterTest.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/BaseFilterTest.java @@ -70,6 +70,7 @@ import org.apache.druid.segment.RowBasedColumnSelectorFactory; import org.apache.druid.segment.RowBasedStorageAdapter; import org.apache.druid.segment.StorageAdapter; import org.apache.druid.segment.VirtualColumns; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.data.BitmapSerdeFactory; import org.apache.druid.segment.data.ConciseBitmapSerdeFactory; @@ -647,10 +648,10 @@ public abstract class BaseFilterTest extends InitializedNullHandlingTest final String selectColumn ) { - // Generate rowType - final Map rowSignature = new HashMap<>(); + // Generate rowSignature + final RowSignature.Builder rowSignatureBuilder = RowSignature.builder(); for (String columnName : Iterables.concat(adapter.getAvailableDimensions(), adapter.getAvailableMetrics())) { - rowSignature.put(columnName, adapter.getColumnCapabilities(columnName).getType()); + rowSignatureBuilder.add(columnName, adapter.getColumnCapabilities(columnName).getType()); } // Perform test @@ -660,7 +661,7 @@ public abstract class BaseFilterTest extends InitializedNullHandlingTest RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), rowSupplier::get, - rowSignature, + rowSignatureBuilder.build(), false ) ) diff --git a/processing/src/test/java/org/apache/druid/segment/join/HashJoinSegmentStorageAdapterTest.java b/processing/src/test/java/org/apache/druid/segment/join/HashJoinSegmentStorageAdapterTest.java index d672a69af7e..892376c9dcc 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/HashJoinSegmentStorageAdapterTest.java +++ b/processing/src/test/java/org/apache/druid/segment/join/HashJoinSegmentStorageAdapterTest.java @@ -68,9 +68,9 @@ public class HashJoinSegmentStorageAdapterTest extends BaseHashJoinSegmentStorag "namespace", "page", "delta", + "c1.countryNumber", "c1.countryIsoCode", - "c1.countryName", - "c1.countryNumber" + "c1.countryName" ), Lists.newArrayList(makeFactToCountrySegment().getAvailableDimensions().iterator()) ); diff --git a/processing/src/test/java/org/apache/druid/segment/join/JoinTestHelper.java b/processing/src/test/java/org/apache/druid/segment/join/JoinTestHelper.java index 8348a284e3c..b63dc522a25 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/JoinTestHelper.java +++ b/processing/src/test/java/org/apache/druid/segment/join/JoinTestHelper.java @@ -22,7 +22,6 @@ package org.apache.druid.segment.join; import com.fasterxml.jackson.databind.MappingIterator; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import org.apache.druid.common.config.NullHandling; @@ -53,6 +52,7 @@ import org.apache.druid.segment.DimensionSelector; import org.apache.druid.segment.IndexBuilder; import org.apache.druid.segment.RowAdapter; import org.apache.druid.segment.TestHelper; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.join.table.RowBasedIndexedTable; @@ -87,18 +87,19 @@ public class JoinTestHelper new StringDimensionSchema("page"), new LongDimensionSchema("delta") ); - private static final Map COUNTRIES_SIGNATURE = - ImmutableMap.builder() - .put("countryNumber", ValueType.LONG) - .put("countryIsoCode", ValueType.STRING) - .put("countryName", ValueType.STRING) - .build(); - private static final Map REGIONS_SIGNATURE = - ImmutableMap.builder() - .put("regionIsoCode", ValueType.STRING) - .put("countryIsoCode", ValueType.STRING) - .put("regionName", ValueType.STRING) - .build(); + private static final RowSignature COUNTRIES_SIGNATURE = + RowSignature.builder() + .add("countryNumber", ValueType.LONG) + .add("countryIsoCode", ValueType.STRING) + .add("countryName", ValueType.STRING) + .build(); + + private static final RowSignature REGIONS_SIGNATURE = + RowSignature.builder() + .add("regionIsoCode", ValueType.STRING) + .add("countryIsoCode", ValueType.STRING) + .add("regionName", ValueType.STRING) + .build(); private static final ColumnProcessorFactory> SIMPLE_READER = new ColumnProcessorFactory>() @@ -140,7 +141,7 @@ public class JoinTestHelper } }; - private static RowAdapter> createMapRowAdapter(final Map signature) + private static RowAdapter> createMapRowAdapter(final RowSignature signature) { return new RowAdapter>() { @@ -153,7 +154,7 @@ public class JoinTestHelper @Override public Function, Object> columnFunction(String columnName) { - final ValueType columnType = signature.get(columnName); + final ValueType columnType = signature.getColumnType(columnName).orElse(null); if (columnType == null) { return row -> row.get(columnName); diff --git a/processing/src/test/java/org/apache/druid/segment/join/JoinableClauseTest.java b/processing/src/test/java/org/apache/druid/segment/join/JoinableClauseTest.java index 9ea6e9773de..1e8357de802 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/JoinableClauseTest.java +++ b/processing/src/test/java/org/apache/druid/segment/join/JoinableClauseTest.java @@ -75,7 +75,7 @@ public class JoinableClauseTest public void test_getAvailableColumnsPrefixed() { Assert.assertEquals( - ImmutableList.of("j.countryIsoCode", "j.countryName", "j.countryNumber"), + ImmutableList.of("j.countryNumber", "j.countryIsoCode", "j.countryName"), clause.getAvailableColumnsPrefixed() ); } diff --git a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinableTest.java b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinableTest.java index a10b699162d..9ed617fde54 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinableTest.java +++ b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinableTest.java @@ -86,7 +86,7 @@ public class IndexedTableJoinableTest public void test_getAvailableColumns() { final IndexedTableJoinable joinable = new IndexedTableJoinable(indexedTable); - Assert.assertEquals(ImmutableList.of("long", "str"), joinable.getAvailableColumns()); + Assert.assertEquals(ImmutableList.of("str", "long"), joinable.getAvailableColumns()); } @Test diff --git a/processing/src/test/java/org/apache/druid/segment/join/table/RowBasedIndexedTableTest.java b/processing/src/test/java/org/apache/druid/segment/join/table/RowBasedIndexedTableTest.java index 92fedcc499b..49ebc36465b 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/table/RowBasedIndexedTableTest.java +++ b/processing/src/test/java/org/apache/druid/segment/join/table/RowBasedIndexedTableTest.java @@ -20,9 +20,9 @@ package org.apache.druid.segment.join.table; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.apache.druid.common.config.NullHandling; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.join.JoinTestHelper; import org.junit.Assert; @@ -38,10 +38,10 @@ import java.util.Map; public class RowBasedIndexedTableTest { // Indexes of fields within the "countries" and "regions" tables. - private static final int INDEX_COUNTRIES_COUNTRY_ISO_CODE = 0; - private static final int INDEX_COUNTRIES_COUNTRY_NAME = 1; - private static final int INDEX_COUNTRIES_COUNTRY_NUMBER = 2; - private static final int INDEX_REGIONS_REGION_ISO_CODE = 1; + private static final int INDEX_COUNTRIES_COUNTRY_NUMBER = 0; + private static final int INDEX_COUNTRIES_COUNTRY_ISO_CODE = 1; + private static final int INDEX_COUNTRIES_COUNTRY_NAME = 2; + private static final int INDEX_REGIONS_REGION_ISO_CODE = 0; @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -68,24 +68,15 @@ public class RowBasedIndexedTableTest Assert.assertEquals(ImmutableSet.of("countryNumber", "countryIsoCode"), countriesTable.keyColumns()); } - @Test - public void test_allColumns_countries() - { - Assert.assertEquals( - ImmutableList.of("countryIsoCode", "countryName", "countryNumber"), - countriesTable.allColumns() - ); - } - @Test public void test_rowSignature_countries() { Assert.assertEquals( - ImmutableMap.builder() - .put("countryIsoCode", ValueType.STRING) - .put("countryName", ValueType.STRING) - .put("countryNumber", ValueType.LONG) - .build(), + RowSignature.builder() + .add("countryNumber", ValueType.LONG) + .add("countryIsoCode", ValueType.STRING) + .add("countryName", ValueType.STRING) + .build(), countriesTable.rowSignature() ); } @@ -125,7 +116,7 @@ public class RowBasedIndexedTableTest @Test public void test_columnIndex_countriesCountryName() { - expectedException.expectMessage("Column[1] is not a key column"); + expectedException.expectMessage("Column[2] is not a key column"); countriesTable.columnIndex(INDEX_COUNTRIES_COUNTRY_NAME); } diff --git a/processing/src/test/java/org/apache/druid/segment/virtual/ExpressionVirtualColumnTest.java b/processing/src/test/java/org/apache/druid/segment/virtual/ExpressionVirtualColumnTest.java index 25648647f7a..5cd87afacc7 100644 --- a/processing/src/test/java/org/apache/druid/segment/virtual/ExpressionVirtualColumnTest.java +++ b/processing/src/test/java/org/apache/druid/segment/virtual/ExpressionVirtualColumnTest.java @@ -48,6 +48,7 @@ import org.apache.druid.segment.RowAdapters; import org.apache.druid.segment.RowBasedColumnSelectorFactory; import org.apache.druid.segment.column.ColumnCapabilities; import org.apache.druid.segment.column.ColumnCapabilitiesImpl; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.data.IndexedInts; import org.apache.druid.testing.InitializedNullHandlingTest; @@ -201,7 +202,7 @@ public class ExpressionVirtualColumnTest extends InitializedNullHandlingTest private static final ColumnSelectorFactory COLUMN_SELECTOR_FACTORY = RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), CURRENT_ROW::get, - null, + RowSignature.empty(), false ); @@ -742,7 +743,7 @@ public class ExpressionVirtualColumnTest extends InitializedNullHandlingTest RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), CURRENT_ROW::get, - ImmutableMap.of("x", ValueType.LONG), + RowSignature.builder().add("x", ValueType.LONG).build(), false ), Parser.parse(SCALE_LONG.getExpression(), TestExprMacroTable.INSTANCE) @@ -765,7 +766,7 @@ public class ExpressionVirtualColumnTest extends InitializedNullHandlingTest RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), CURRENT_ROW::get, - ImmutableMap.of("x", ValueType.DOUBLE), + RowSignature.builder().add("x", ValueType.DOUBLE).build(), false ), Parser.parse(SCALE_FLOAT.getExpression(), TestExprMacroTable.INSTANCE) @@ -788,7 +789,7 @@ public class ExpressionVirtualColumnTest extends InitializedNullHandlingTest RowBasedColumnSelectorFactory.create( RowAdapters.standardRow(), CURRENT_ROW::get, - ImmutableMap.of("x", ValueType.FLOAT), + RowSignature.builder().add("x", ValueType.FLOAT).build(), false ), Parser.parse(SCALE_FLOAT.getExpression(), TestExprMacroTable.INSTANCE) diff --git a/server/src/test/java/org/apache/druid/client/CachingClusteredClientTest.java b/server/src/test/java/org/apache/druid/client/CachingClusteredClientTest.java index 25c027e9e56..2a869303012 100644 --- a/server/src/test/java/org/apache/druid/client/CachingClusteredClientTest.java +++ b/server/src/test/java/org/apache/druid/client/CachingClusteredClientTest.java @@ -2348,7 +2348,7 @@ public class CachingClusteredClientTest } for (Map.Entry entry : rowMap.entrySet()) { - final int position = query.getResultRowPositionLookup().getInt(entry.getKey()); + final int position = query.getResultRowSignature().indexOf(entry.getKey()); row.set(position, entry.getValue()); } diff --git a/server/src/test/java/org/apache/druid/segment/join/InlineJoinableFactoryTest.java b/server/src/test/java/org/apache/druid/segment/join/InlineJoinableFactoryTest.java index 50a4a93a8e3..764668acd70 100644 --- a/server/src/test/java/org/apache/druid/segment/join/InlineJoinableFactoryTest.java +++ b/server/src/test/java/org/apache/druid/segment/join/InlineJoinableFactoryTest.java @@ -75,7 +75,7 @@ public class InlineJoinableFactoryTest final Joinable joinable = factory.build(inlineDataSource, makeCondition("x == \"j.long\"")).get(); Assert.assertThat(joinable, CoreMatchers.instanceOf(IndexedTableJoinable.class)); - Assert.assertEquals(ImmutableList.of("long", "str"), joinable.getAvailableColumns()); + Assert.assertEquals(ImmutableList.of("str", "long"), joinable.getAvailableColumns()); Assert.assertEquals(2, joinable.getCardinality("str")); Assert.assertEquals(2, joinable.getCardinality("long")); } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregation.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregation.java index 4b4dbd5f1bc..41ce1616769 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregation.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregation.java @@ -30,9 +30,9 @@ import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.filter.AndDimFilter; import org.apache.druid.query.filter.DimFilter; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregations.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregations.java index d54b20caeb8..65419d0e2ea 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregations.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/Aggregations.java @@ -22,11 +22,11 @@ package org.apache.druid.sql.calcite.aggregation; import org.apache.calcite.rel.core.AggregateCall; import org.apache.calcite.rel.core.Project; import org.apache.calcite.rex.RexNode; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; @@ -90,7 +90,7 @@ public class Aggregations if (druidExpression.isSimpleExtraction() && (!druidExpression.isDirectColumnAccess() - || rowSignature.getColumnType(druidExpression.getDirectColumn()) == ValueType.STRING)) { + || rowSignature.getColumnType(druidExpression.getDirectColumn()).orElse(null) == ValueType.STRING)) { // Aggregators are unable to implicitly cast strings to numbers. // So remove the simple extraction, which forces the expression to be used instead of the direct column access. return druidExpression.map(simpleExtraction -> null, Function.identity()); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/SqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/SqlAggregator.java index abefedeebda..d21f6ebb75a 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/SqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/SqlAggregator.java @@ -23,9 +23,9 @@ import org.apache.calcite.rel.core.AggregateCall; import org.apache.calcite.rel.core.Project; import org.apache.calcite.rex.RexBuilder; import org.apache.calcite.sql.SqlAggFunction; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/ApproxCountDistinctSqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/ApproxCountDistinctSqlAggregator.java index 21cf7368f02..2c15bf214e2 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/ApproxCountDistinctSqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/ApproxCountDistinctSqlAggregator.java @@ -40,6 +40,7 @@ import org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFact import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -48,7 +49,6 @@ import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; @@ -97,7 +97,8 @@ public class ApproxCountDistinctSqlAggregator implements SqlAggregator final AggregatorFactory aggregatorFactory; final String aggregatorName = finalizeAggregations ? Calcites.makePrefixedName(name, "a") : name; - if (arg.isDirectColumnAccess() && rowSignature.getColumnType(arg.getDirectColumn()) == ValueType.COMPLEX) { + if (arg.isDirectColumnAccess() + && rowSignature.getColumnType(arg.getDirectColumn()).orElse(null) == ValueType.COMPLEX) { aggregatorFactory = new HyperUniquesAggregatorFactory(aggregatorName, arg.getDirectColumn(), false, true); } else { final SqlTypeName sqlTypeName = rexNode.getType().getSqlTypeName(); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/CountSqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/CountSqlAggregator.java index 4bf35e11764..6bf8b601be9 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/CountSqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/CountSqlAggregator.java @@ -30,6 +30,7 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.druid.java.util.common.ISE; import org.apache.druid.query.aggregation.CountAggregatorFactory; import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.Aggregations; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -37,7 +38,6 @@ import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java index db73bc14119..063ea1b7056 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/EarliestLatestAnySqlAggregator.java @@ -48,6 +48,7 @@ import org.apache.druid.query.aggregation.last.LongLastAggregatorFactory; import org.apache.druid.query.aggregation.last.StringLastAggregatorFactory; import org.apache.druid.query.aggregation.post.FinalizingFieldAccessPostAggregator; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; @@ -56,7 +57,6 @@ import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.Collections; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/MultiColumnSqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/MultiColumnSqlAggregator.java index b8a66747d6e..4c7efb7c0b0 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/MultiColumnSqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/MultiColumnSqlAggregator.java @@ -27,6 +27,7 @@ import org.apache.druid.math.expr.ExprMacroTable; import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.Aggregations; @@ -35,7 +36,6 @@ import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/SimpleSqlAggregator.java b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/SimpleSqlAggregator.java index 57b9ad87605..0f7f937e3e0 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/SimpleSqlAggregator.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/aggregation/builtin/SimpleSqlAggregator.java @@ -24,13 +24,13 @@ import org.apache.calcite.rel.core.AggregateCall; import org.apache.calcite.rel.core.Project; import org.apache.calcite.rex.RexBuilder; import org.apache.druid.math.expr.ExprMacroTable; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.Aggregations; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/AliasedOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/AliasedOperatorConversion.java index 01b9530e66d..47e364f196d 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/AliasedOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/AliasedOperatorConversion.java @@ -26,9 +26,9 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.druid.java.util.common.IAE; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/BinaryOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/BinaryOperatorConversion.java index 25d895f9248..8199e3b4a87 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/BinaryOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/BinaryOperatorConversion.java @@ -24,8 +24,8 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.stream.Collectors; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/DirectOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/DirectOperatorConversion.java index a6c67dfa654..4246e4710a6 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/DirectOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/DirectOperatorConversion.java @@ -21,8 +21,8 @@ package org.apache.druid.sql.calcite.expression; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java index be9d3cc72e5..b0c7c59421e 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/Expressions.java @@ -53,6 +53,7 @@ import org.apache.druid.query.ordering.StringComparator; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.VirtualColumn; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.filtration.BoundRefKey; import org.apache.druid.sql.calcite.filtration.Bounds; @@ -60,7 +61,7 @@ import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import org.joda.time.Interval; import javax.annotation.Nullable; @@ -94,7 +95,7 @@ public class Expressions { if (project == null) { // I don't think the factory impl matters here. - return RexInputRef.of(fieldNumber, rowSignature.getRelDataType(new JavaTypeFactoryImpl())); + return RexInputRef.of(fieldNumber, RowSignatures.toRelDataType(rowSignature, new JavaTypeFactoryImpl())); } else { return project.getChildExps().get(fieldNumber); } @@ -132,9 +133,9 @@ public class Expressions /** * Translate a list of Calcite {@code RexNode} to Druid expressions, with the possibility of having postagg operands. * - * @param plannerContext SQL planner context - * @param rowSignature signature of the rows to be extracted from - * @param rexNodes list of Calcite expressions meant to be applied on top of the rows + * @param plannerContext SQL planner context + * @param rowSignature signature of the rows to be extracted from + * @param rexNodes list of Calcite expressions meant to be applied on top of the rows * @param postAggregatorVisitor visitor that manages postagg names and tracks postaggs that were created as * by the translation * @@ -218,7 +219,7 @@ public class Expressions { // Translate field references. final RexInputRef ref = (RexInputRef) rexNode; - final String columnName = rowSignature.getRowOrder().get(ref.getIndex()); + final String columnName = rowSignature.getColumnName(ref.getIndex()); if (columnName == null) { throw new ISE("WTF?! Expression referred to nonexistent index[%d]", ref.getIndex()); } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/OperatorConversions.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/OperatorConversions.java index b719cad892a..6b4a4539bee 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/OperatorConversions.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/OperatorConversions.java @@ -50,10 +50,10 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.ISE; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.DruidTypeSystem; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.Arrays; @@ -171,12 +171,12 @@ public class OperatorConversions /** * Translate a Calcite {@code RexNode} to a Druid PostAggregator * - * @param plannerContext SQL planner context - * @param rowSignature signature of the rows to be extracted from - * @param rexNode expression meant to be applied on top of the rows - * + * @param plannerContext SQL planner context + * @param rowSignature signature of the rows to be extracted from + * @param rexNode expression meant to be applied on top of the rows * @param postAggregatorVisitor visitor that manages postagg names and tracks postaggs that were created * by the translation + * * @return rexNode referring to fields in rowOrder, or null if not possible */ @Nullable @@ -191,7 +191,7 @@ public class OperatorConversions if (kind == SqlKind.INPUT_REF) { // Translate field references. final RexInputRef ref = (RexInputRef) rexNode; - final String columnName = rowSignature.getRowOrder().get(ref.getIndex()); + final String columnName = rowSignature.getColumnName(ref.getIndex()); if (columnName == null) { throw new ISE("WTF?! PostAgg referred to nonexistent index[%d]", ref.getIndex()); } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/SqlOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/SqlOperatorConversion.java index f69ede61909..ca269ee336f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/SqlOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/SqlOperatorConversion.java @@ -23,9 +23,9 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryFunctionOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryFunctionOperatorConversion.java index 419a1bf2e53..1aac3545f3e 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryFunctionOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryFunctionOperatorConversion.java @@ -23,8 +23,8 @@ import com.google.common.collect.Iterables; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class UnaryFunctionOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryPrefixOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryPrefixOperatorConversion.java index 9bd3961a189..09d25b63165 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryPrefixOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnaryPrefixOperatorConversion.java @@ -23,8 +23,8 @@ import com.google.common.collect.Iterables; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class UnaryPrefixOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnarySuffixOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnarySuffixOperatorConversion.java index 64b6deaf2a1..6595b2bf3d6 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnarySuffixOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/UnarySuffixOperatorConversion.java @@ -23,8 +23,8 @@ import com.google.common.collect.Iterables; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class UnarySuffixOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayConstructorOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayConstructorOperatorConversion.java index c4031c286d6..6c3a38db3e2 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayConstructorOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayConstructorOperatorConversion.java @@ -22,11 +22,11 @@ package org.apache.druid.sql.calcite.expression.builtin; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayConstructorOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayContainsOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayContainsOperatorConversion.java index 2bfe51ea055..a4a9c0de815 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayContainsOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayContainsOperatorConversion.java @@ -30,12 +30,12 @@ import org.apache.druid.math.expr.ExprEval; import org.apache.druid.math.expr.Parser; import org.apache.druid.query.filter.AndDimFilter; import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.Arrays; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayLengthOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayLengthOperatorConversion.java index ac641850e8c..bcafbb605c6 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayLengthOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayLengthOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayLengthOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOfOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOfOperatorConversion.java index 0f4a09733b6..2e06ef9aa29 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOfOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOfOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayOffsetOfOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOperatorConversion.java index 6fb16604fac..42a874da5e4 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOffsetOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayOffsetOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOfOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOfOperatorConversion.java index 83b93595dc6..367d80ff1cc 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOfOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOfOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayOrdinalOfOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOperatorConversion.java index 71fb4a51b4a..1dd9c4a800d 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOrdinalOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayOrdinalOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOverlapOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOverlapOperatorConversion.java index 57ef4b51bbe..175670ec829 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOverlapOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayOverlapOperatorConversion.java @@ -31,12 +31,12 @@ import org.apache.druid.math.expr.ExprEval; import org.apache.druid.math.expr.Parser; import org.apache.druid.query.filter.DimFilter; import org.apache.druid.query.filter.InDimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayToStringOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayToStringOperatorConversion.java index 12ff2e10ea6..3d9331fa710 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayToStringOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ArrayToStringOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ArrayToStringOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/BTrimOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/BTrimOperatorConversion.java index 74098ddc825..4e45c5a0fd9 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/BTrimOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/BTrimOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlTrimFunction; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class BTrimOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java index c9c752e8050..51a42b41140 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java @@ -30,11 +30,11 @@ import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.PeriodGranularity; import org.apache.druid.math.expr.ExprType; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.Period; import java.util.Map; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CeilOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CeilOperatorConversion.java index d11f84cbf2c..77baafb796f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CeilOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CeilOperatorConversion.java @@ -23,11 +23,11 @@ import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ConcatOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ConcatOperatorConversion.java index 1d49b5092ea..e7dbf504614 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ConcatOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ConcatOperatorConversion.java @@ -26,12 +26,12 @@ import org.apache.calcite.sql.SqlKind; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ConcatOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/DateTruncOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/DateTruncOperatorConversion.java index bd6add35547..9e4bf3c3d50 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/DateTruncOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/DateTruncOperatorConversion.java @@ -31,11 +31,11 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.math.expr.Expr; import org.apache.druid.math.expr.Parser; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.Period; import java.util.Map; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java index 633a3d63656..cf53c941e9f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ExtractOperatorConversion.java @@ -27,11 +27,11 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlFunction; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.druid.query.expression.TimestampExtractExprMacro; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import java.util.Map; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/FloorOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/FloorOperatorConversion.java index b8903438161..d27c1e7b2a1 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/FloorOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/FloorOperatorConversion.java @@ -23,11 +23,11 @@ import org.apache.calcite.rex.RexCall; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LPadOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LPadOperatorConversion.java index f7fdb12ded1..6a2d4f59b6e 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LPadOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LPadOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class LPadOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LTrimOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LTrimOperatorConversion.java index 4dfe3f62bf3..d3ac45da0fc 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LTrimOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LTrimOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlTrimFunction; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class LTrimOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LeftOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LeftOperatorConversion.java index 65aeecaa3d2..7363974eb79 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LeftOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LeftOperatorConversion.java @@ -26,12 +26,12 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class LeftOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LikeOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LikeOperatorConversion.java index 8019f279dc8..eb7350840ee 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LikeOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/LikeOperatorConversion.java @@ -27,12 +27,12 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.druid.query.filter.DimFilter; import org.apache.druid.query.filter.LikeDimFilter; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DirectOperatorConversion; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MillisToTimestampOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MillisToTimestampOperatorConversion.java index 9d28fc212f7..227279f5a2f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MillisToTimestampOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MillisToTimestampOperatorConversion.java @@ -27,12 +27,12 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class MillisToTimestampOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringAppendOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringAppendOperatorConversion.java index 171f6edb9d2..fb4745425ad 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringAppendOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringAppendOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class MultiValueStringAppendOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringConcatOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringConcatOperatorConversion.java index 60bc54ab2ba..03e1c7c63bc 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringConcatOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringConcatOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class MultiValueStringConcatOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringPrependOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringPrependOperatorConversion.java index be817e1fb01..4b7cc968df1 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringPrependOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringPrependOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class MultiValueStringPrependOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringSliceOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringSliceOperatorConversion.java index 56348a315b6..cba6ee66eec 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringSliceOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/MultiValueStringSliceOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class MultiValueStringSliceOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java index 3230f684052..29b0906e417 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ParseLongOperatorConversion.java @@ -25,11 +25,11 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ParseLongOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/PositionOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/PositionOperatorConversion.java index 3b4baf6ce8a..28638716c6f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/PositionOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/PositionOperatorConversion.java @@ -24,11 +24,11 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class PositionOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/QueryLookupOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/QueryLookupOperatorConversion.java index 3b6607d208e..4fa27af7503 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/QueryLookupOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/QueryLookupOperatorConversion.java @@ -29,11 +29,11 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.math.expr.Expr; import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider; import org.apache.druid.query.lookup.RegisteredLookupExtractionFn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class QueryLookupOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RPadOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RPadOperatorConversion.java index e2bc5d2b81f..68874ef86ba 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RPadOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RPadOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class RPadOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RTrimOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RTrimOperatorConversion.java index 0520a080d1a..8361a8a5e8f 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RTrimOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RTrimOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlTrimFunction; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class RTrimOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RegexpExtractOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RegexpExtractOperatorConversion.java index 3959e2234f0..18da1b31bff 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RegexpExtractOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RegexpExtractOperatorConversion.java @@ -27,11 +27,11 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.math.expr.Expr; import org.apache.druid.query.extraction.RegexDimExtractionFn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class RegexpExtractOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RepeatOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RepeatOperatorConversion.java index a15cab11fcf..318e95d9b4b 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RepeatOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RepeatOperatorConversion.java @@ -26,12 +26,12 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class RepeatOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ReverseOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ReverseOperatorConversion.java index 9b3a434b296..7cb0f055297 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ReverseOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/ReverseOperatorConversion.java @@ -25,11 +25,11 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class ReverseOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RightOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RightOperatorConversion.java index a2274bb83c9..9fc3736d9f6 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RightOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RightOperatorConversion.java @@ -26,12 +26,12 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class RightOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RoundOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RoundOperatorConversion.java index 558a1b9cda0..85b569457ff 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RoundOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/RoundOperatorConversion.java @@ -24,11 +24,11 @@ import org.apache.calcite.sql.SqlFunction; import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.type.SqlTypeFamily; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class RoundOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringFormatOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringFormatOperatorConversion.java index d64040eb7c9..3a535cdd9ea 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringFormatOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringFormatOperatorConversion.java @@ -30,11 +30,11 @@ import org.apache.calcite.sql.type.SqlOperandCountRanges; import org.apache.calcite.sql.type.SqlOperandTypeChecker; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class StringFormatOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringToMultiValueStringOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringToMultiValueStringOperatorConversion.java index 4422605ed5a..bdb590888aa 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringToMultiValueStringOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StringToMultiValueStringOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.OperandTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class StringToMultiValueStringOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StrposOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StrposOperatorConversion.java index 2fd0f09a082..336c9d3b372 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StrposOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/StrposOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class StrposOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/SubstringOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/SubstringOperatorConversion.java index de1ee2accef..5ff240fc524 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/SubstringOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/SubstringOperatorConversion.java @@ -29,12 +29,12 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.extraction.SubstringDimExtractionFn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class SubstringOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TextcatOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TextcatOperatorConversion.java index b678558a4b0..09652ee08ff 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TextcatOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TextcatOperatorConversion.java @@ -24,11 +24,11 @@ import org.apache.calcite.sql.SqlFunction; import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class TextcatOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeArithmeticOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeArithmeticOperatorConversion.java index 6f7b412adda..4ff15d6a6f2 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeArithmeticOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeArithmeticOperatorConversion.java @@ -28,11 +28,11 @@ import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeCeilOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeCeilOperatorConversion.java index 4bfa3f7418a..8b2ee0c7e78 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeCeilOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeCeilOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java index c8d7f3e85fa..ea041cfee2a 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeExtractOperatorConversion.java @@ -30,12 +30,12 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.query.expression.TimestampExtractExprMacro; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.DateTimeZone; public class TimeExtractOperatorConversion implements SqlOperatorConversion diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFloorOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFloorOperatorConversion.java index b903c3b0a52..af2716e39c6 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFloorOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFloorOperatorConversion.java @@ -34,6 +34,7 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.granularity.PeriodGranularity; import org.apache.druid.math.expr.ExprMacroTable; import org.apache.druid.query.expression.TimestampFloorExprMacro; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; @@ -41,7 +42,6 @@ import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.expression.TimeUnits; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.Period; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFormatOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFormatOperatorConversion.java index e91afdad8e2..fa988a38a97 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFormatOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeFormatOperatorConversion.java @@ -29,12 +29,12 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.DateTimeZone; import java.util.stream.Collectors; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeParseOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeParseOperatorConversion.java index de0068d5e59..8bba7321ac4 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeParseOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeParseOperatorConversion.java @@ -29,12 +29,12 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.DateTimeZone; import java.util.stream.Collectors; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeShiftOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeShiftOperatorConversion.java index 0eebbebae02..4ca033a2914 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeShiftOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimeShiftOperatorConversion.java @@ -29,12 +29,12 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.DateTimeZone; import java.util.stream.Collectors; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimestampToMillisOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimestampToMillisOperatorConversion.java index 5b6fad79cfd..ec1742d03c8 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimestampToMillisOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TimestampToMillisOperatorConversion.java @@ -27,12 +27,12 @@ import org.apache.calcite.sql.SqlFunctionCategory; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class TimestampToMillisOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TrimOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TrimOperatorConversion.java index b35caa8cb80..75d3416d3c5 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TrimOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TrimOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.fun.SqlStdOperatorTable; import org.apache.calcite.sql.fun.SqlTrimFunction; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TruncateOperatorConversion.java b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TruncateOperatorConversion.java index 4f4b122f0a0..b4eae666157 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TruncateOperatorConversion.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/TruncateOperatorConversion.java @@ -26,11 +26,11 @@ import org.apache.calcite.sql.type.ReturnTypes; import org.apache.calcite.sql.type.SqlTypeFamily; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.math.expr.Expr; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.SqlOperatorConversion; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; public class TruncateOperatorConversion implements SqlOperatorConversion { diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertBoundsToSelectors.java b/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertBoundsToSelectors.java index f93407a0280..155e7a632cc 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertBoundsToSelectors.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertBoundsToSelectors.java @@ -23,8 +23,9 @@ import org.apache.druid.query.filter.BoundDimFilter; import org.apache.druid.query.filter.DimFilter; import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.query.ordering.StringComparator; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.SimpleExtraction; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; public class ConvertBoundsToSelectors extends BottomUpTransform { @@ -45,7 +46,8 @@ public class ConvertBoundsToSelectors extends BottomUpTransform { if (filter instanceof BoundDimFilter) { final BoundDimFilter bound = (BoundDimFilter) filter; - final StringComparator comparator = rowSignature.naturalStringComparator( + final StringComparator comparator = RowSignatures.getNaturalStringComparator( + rowSignature, SimpleExtraction.of(bound.getDimension(), bound.getExtractionFn()) ); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertSelectorsToIns.java b/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertSelectorsToIns.java index 043111c9359..83da05716c3 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertSelectorsToIns.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/filtration/ConvertSelectorsToIns.java @@ -25,8 +25,9 @@ import org.apache.druid.query.filter.DimFilter; import org.apache.druid.query.filter.InDimFilter; import org.apache.druid.query.filter.OrDimFilter; import org.apache.druid.query.filter.SelectorDimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.SimpleExtraction; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import java.util.ArrayList; import java.util.HashMap; @@ -62,7 +63,8 @@ public class ConvertSelectorsToIns extends BottomUpTransform final SelectorDimFilter selector = (SelectorDimFilter) child; final BoundRefKey boundRefKey = BoundRefKey.from( selector, - sourceRowSignature.naturalStringComparator( + RowSignatures.getNaturalStringComparator( + sourceRowSignature, SimpleExtraction.of(selector.getDimension(), selector.getExtractionFn()) ) ); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/filtration/Filtration.java b/sql/src/main/java/org/apache/druid/sql/calcite/filtration/Filtration.java index 4342804f935..677961eacea 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/filtration/Filtration.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/filtration/Filtration.java @@ -28,7 +28,7 @@ import org.apache.druid.query.filter.DimFilter; import org.apache.druid.query.filter.ExpressionDimFilter; import org.apache.druid.query.spec.MultipleIntervalSegmentSpec; import org.apache.druid.query.spec.QuerySegmentSpec; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.segment.column.RowSignature; import org.joda.time.Interval; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRexExecutor.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRexExecutor.java index 48c13c08938..31244d13b49 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRexExecutor.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRexExecutor.java @@ -30,9 +30,9 @@ import org.apache.druid.math.expr.Expr; import org.apache.druid.math.expr.ExprEval; import org.apache.druid.math.expr.ExprType; import org.apache.druid.math.expr.Parser; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; -import org.apache.druid.sql.calcite.table.RowSignature; import java.math.BigDecimal; import java.util.Arrays; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidJoinQueryRel.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidJoinQueryRel.java index 1142188bc2a..0e9094bc85c 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidJoinQueryRel.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidJoinQueryRel.java @@ -42,11 +42,12 @@ import org.apache.druid.query.DataSource; import org.apache.druid.query.JoinDataSource; import org.apache.druid.query.QueryDataSource; import org.apache.druid.query.TableDataSource; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.join.JoinType; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.planner.Calcites; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import java.util.HashSet; import java.util.List; @@ -190,7 +191,7 @@ public class DruidJoinQueryRel extends DruidRel { return partialQuery.build( DUMMY_DATA_SOURCE, - RowSignature.from( + RowSignatures.fromRelDataType( joinRel.getRowType().getFieldNames(), joinRel.getRowType() ), @@ -328,15 +329,15 @@ public class DruidJoinQueryRel extends DruidRel { final RowSignature.Builder signatureBuilder = RowSignature.builder(); - for (final String column : leftSignature.getRowOrder()) { - signatureBuilder.add(column, leftSignature.getColumnType(column)); + for (final String column : leftSignature.getColumnNames()) { + signatureBuilder.add(column, leftSignature.getColumnType(column).orElse(null)); } // Need to include the "0" since findUnusedPrefixForDigits only guarantees safety for digit-initiated suffixes - final String rightPrefix = Calcites.findUnusedPrefixForDigits("j", leftSignature.getRowOrder()) + "0."; + final String rightPrefix = Calcites.findUnusedPrefixForDigits("j", leftSignature.getColumnNames()) + "0."; - for (final String column : rightSignature.getRowOrder()) { - signatureBuilder.add(rightPrefix + column, rightSignature.getColumnType(column)); + for (final String column : rightSignature.getColumnNames()) { + signatureBuilder.add(rightPrefix + column, rightSignature.getColumnType(column).orElse(null)); } return Pair.of(rightPrefix, signatureBuilder.build()); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidOuterQueryRel.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidOuterQueryRel.java index d80bca6ba60..fde3457e53d 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidOuterQueryRel.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidOuterQueryRel.java @@ -37,7 +37,8 @@ import org.apache.druid.java.util.common.guava.Sequences; import org.apache.druid.query.QueryDataSource; import org.apache.druid.query.TableDataSource; import org.apache.druid.query.groupby.GroupByQuery; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.segment.column.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import javax.annotation.Nullable; import java.util.List; @@ -150,7 +151,7 @@ public class DruidOuterQueryRel extends DruidRel { return partialQuery.build( DUMMY_DATA_SOURCE, - RowSignature.from( + RowSignatures.fromRelDataType( sourceRel.getRowType().getFieldNames(), sourceRel.getRowType() ), diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidQuery.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidQuery.java index dfb3f1669ae..04c899aacb4 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidQuery.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidQuery.java @@ -68,6 +68,7 @@ import org.apache.druid.query.topn.TopNQuery; import org.apache.druid.segment.VirtualColumn; import org.apache.druid.segment.VirtualColumns; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.DimensionExpression; @@ -77,7 +78,7 @@ import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rule.GroupByRules; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -88,7 +89,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeSet; /** * A fully formed Druid query, built from a {@link PartialDruidQuery}. The work to develop this query is done @@ -331,7 +331,7 @@ public class DruidQuery finalizeAggregations ); - final RowSignature aggregateRowSignature = RowSignature.from( + final RowSignature aggregateRowSignature = RowSignatures.fromRelDataType( ImmutableList.copyOf( Iterators.concat( dimensions.stream().map(DimensionExpression::getOutputName).iterator(), @@ -377,7 +377,8 @@ public class DruidQuery { final Aggregate aggregate = Preconditions.checkNotNull(partialQuery.getAggregate()); final List dimensions = new ArrayList<>(); - final String outputNamePrefix = Calcites.findUnusedPrefixForDigits("d", new TreeSet<>(rowSignature.getRowOrder())); + final String outputNamePrefix = Calcites.findUnusedPrefixForDigits("d", rowSignature.getColumnNames()); + int outputNameCounter = 0; for (int i : aggregate.getGroupSet()) { @@ -409,7 +410,12 @@ public class DruidQuery druidExpression, sqlTypeName ); - dimensions.add(DimensionExpression.ofVirtualColumn(virtualColumn.getOutputName(), dimOutputName, druidExpression, outputType)); + dimensions.add(DimensionExpression.ofVirtualColumn( + virtualColumn.getOutputName(), + dimOutputName, + druidExpression, + outputType + )); } else { dimensions.add(DimensionExpression.ofSimpleColumn(dimOutputName, druidExpression, outputType)); } @@ -429,7 +435,7 @@ public class DruidQuery final Aggregate aggregate = partialQuery.getAggregate(); // dimBitMapping maps from input field position to group set position (dimension number). - final int[] dimBitMapping = new int[rowSignature.getRowOrder().size()]; + final int[] dimBitMapping = new int[rowSignature.size()]; int i = 0; for (int dimBit : aggregate.getGroupSet()) { dimBitMapping[dimBit] = i++; @@ -477,7 +483,7 @@ public class DruidQuery { final Aggregate aggregate = Preconditions.checkNotNull(partialQuery.getAggregate()); final List aggregations = new ArrayList<>(); - final String outputNamePrefix = Calcites.findUnusedPrefixForDigits("a", new TreeSet<>(rowSignature.getRowOrder())); + final String outputNamePrefix = Calcites.findUnusedPrefixForDigits("a", rowSignature.getColumnNames()); for (int i = 0; i < aggregate.getAggCallList().size(); i++) { final String aggName = outputNamePrefix + i; @@ -536,7 +542,7 @@ public class DruidQuery } else if (collation.getDirection() == RelFieldCollation.Direction.DESCENDING) { direction = OrderByColumnSpec.Direction.DESCENDING; } else { - throw new ISE("WTF?! Don't know what to do with direction[%s]", collation.getDirection()); + throw new ISE("Don't know what to do with direction[%s]", collation.getDirection()); } final SqlTypeName sortExpressionType = sortExpression.getType().getSqlTypeName(); @@ -550,7 +556,7 @@ public class DruidQuery if (sortExpression.isA(SqlKind.INPUT_REF)) { final RexInputRef ref = (RexInputRef) sortExpression; - final String fieldName = rowSignature.getRowOrder().get(ref.getIndex()); + final String fieldName = rowSignature.getColumnName(ref.getIndex()); orderBys.add(new OrderByColumnSpec(fieldName, direction, comparator)); } else { // We don't support sorting by anything other than refs which actually appear in the query result. @@ -936,10 +942,9 @@ public class DruidQuery return null; } - - if (outputRowSignature.getRowOrder().isEmpty()) { + if (outputRowSignature.size() == 0) { // Should never do a scan query without any columns that we're interested in. This is probably a planner bug. - throw new ISE("WTF?! Attempting to convert to Scan query without any columns?"); + throw new ISE("Cannot convert to Scan query without any columns."); } final Filtration filtration = Filtration.create(filter).optimize(virtualColumnRegistry.getFullRowSignature()); @@ -970,7 +975,7 @@ public class DruidQuery } // Compute the list of columns to select. - final Set columns = new HashSet<>(outputRowSignature.getRowOrder()); + final Set columns = new HashSet<>(outputRowSignature.getColumnNames()); if (order != ScanQuery.Order.NONE) { columns.add(ColumnHolder.TIME_COLUMN_NAME); } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/Grouping.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/Grouping.java index 6e1b03ba0ea..0a954729f70 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/Grouping.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/Grouping.java @@ -32,10 +32,10 @@ import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.dimension.DimensionSpec; import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.DimensionExpression; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.ArrayList; @@ -96,7 +96,7 @@ public class Grouping } // Verify that items in the output signature exist. - for (final String field : outputRowSignature.getRowOrder()) { + for (final String field : outputRowSignature.getColumnNames()) { if (!seen.contains(field)) { throw new ISE("Missing field in rowOrder: %s", field); } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java index 7738c92ad47..9605075c09c 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/PartialDruidQuery.java @@ -35,8 +35,8 @@ import org.apache.calcite.rex.RexUtil; import org.apache.calcite.tools.RelBuilder; import org.apache.druid.java.util.common.ISE; import org.apache.druid.query.DataSource; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import java.util.List; import java.util.Objects; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/Projection.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/Projection.java index 16b67928d2d..44a4705d082 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/Projection.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/Projection.java @@ -25,11 +25,13 @@ import org.apache.calcite.rel.core.Project; import org.apache.calcite.rex.RexNode; import org.apache.calcite.sql.SqlKind; import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.ISE; import org.apache.druid.math.expr.ExprType; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ExpressionPostAggregator; import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.Expressions; @@ -37,7 +39,7 @@ import org.apache.druid.sql.calcite.expression.OperatorConversions; import org.apache.druid.sql.calcite.expression.PostAggregatorVisitor; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import javax.annotation.Nullable; import java.util.ArrayList; @@ -45,7 +47,6 @@ import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.TreeSet; /** * Used to represent projections (Calcite "Project"). These are embedded in {@link Sorting} and {@link Grouping} to @@ -197,10 +198,7 @@ public class Projection ) { final List rowOrder = new ArrayList<>(); - final String outputNamePrefix = Calcites.findUnusedPrefixForDigits( - basePrefix, - new TreeSet<>(inputRowSignature.getRowOrder()) - ); + final String outputNamePrefix = Calcites.findUnusedPrefixForDigits(basePrefix, inputRowSignature.getColumnNames()); final PostAggregatorVisitor postAggVisitor = new PostAggregatorVisitor(outputNamePrefix); for (final RexNode postAggregatorRexNode : project.getChildExps()) { @@ -225,7 +223,11 @@ public class Projection } } - return new Projection(postAggVisitor.getPostAggs(), null, RowSignature.from(rowOrder, project.getRowType())); + return new Projection( + postAggVisitor.getPostAggs(), + null, + RowSignatures.fromRelDataType(rowOrder, project.getRowType()) + ); } public static Projection preAggregation( @@ -272,7 +274,7 @@ public class Projection return new Projection( null, ImmutableList.copyOf(virtualColumns), - RowSignature.from(rowOrder, project.getRowType()) + RowSignatures.fromRelDataType(rowOrder, project.getRowType()) ); } @@ -297,7 +299,12 @@ public class Projection } // We don't really have a way to cast complex type. So might as well not do anything and return. - final ValueType columnValueType = aggregateRowSignature.getColumnType(expression.getDirectColumn()); + final ValueType columnValueType = + aggregateRowSignature.getColumnType(expression.getDirectColumn()) + .orElseThrow( + () -> new ISE("Encountered null type for column[%s]", expression.getDirectColumn()) + ); + if (columnValueType == ValueType.COMPLEX) { return true; } @@ -332,7 +339,12 @@ public class Projection } // Check if a cast is necessary. - final ValueType toValueType = aggregateRowSignature.getColumnType(expression.getDirectColumn()); + final ValueType toValueType = + aggregateRowSignature.getColumnType(expression.getDirectColumn()) + .orElseThrow( + () -> new ISE("Encountered null type for column[%s]", expression.getDirectColumn()) + ); + final ValueType fromValueType = Calcites.getValueTypeForSqlTypeName(rexNode.getType().getSqlTypeName()); return toValueType == ValueType.COMPLEX && fromValueType == ValueType.COMPLEX; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/QueryMaker.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/QueryMaker.java index 5aacb8773f3..d73312e98ac 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/QueryMaker.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/QueryMaker.java @@ -104,11 +104,11 @@ public class QueryMaker // just as fast as a timeseries query (a noble goal) we can remove timeseries queries from the SQL layer and // also remove this hack. final String timeDimension = Iterables.getOnlyElement(druidQuery.getGrouping().getDimensions()).getOutputName(); - rowOrder = druidQuery.getOutputRowSignature().getRowOrder().stream() + rowOrder = druidQuery.getOutputRowSignature().getColumnNames().stream() .map(f -> timeDimension.equals(f) ? ColumnHolder.TIME_COLUMN_NAME : f) .collect(Collectors.toList()); } else { - rowOrder = druidQuery.getOutputRowSignature().getRowOrder(); + rowOrder = druidQuery.getOutputRowSignature().getColumnNames(); } return execute( @@ -153,7 +153,7 @@ public class QueryMaker //noinspection unchecked final QueryToolChest> toolChest = queryLifecycle.getToolChest(); - final List resultArrayFields = toolChest.resultArrayFields(query); + final List resultArrayFields = toolChest.resultArraySignature(query).getColumnNames(); final Sequence resultArrays = toolChest.resultsAsArrays(query, results); return remapFields(resultArrays, resultArrayFields, newFields, newTypes); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rel/VirtualColumnRegistry.java b/sql/src/main/java/org/apache/druid/sql/calcite/rel/VirtualColumnRegistry.java index a4a0d25b98b..699fb74d62b 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rel/VirtualColumnRegistry.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rel/VirtualColumnRegistry.java @@ -21,15 +21,14 @@ package org.apache.druid.sql.calcite.rel; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; -import java.util.TreeSet; /** * Provides facilities to create and re-use {@link VirtualColumn} definitions for dimensions, filters, and filtered @@ -60,7 +59,7 @@ public class VirtualColumnRegistry { return new VirtualColumnRegistry( rowSignature, - Calcites.findUnusedPrefixForDigits("v", new TreeSet<>(rowSignature.getRowOrder())), + Calcites.findUnusedPrefixForDigits("v", rowSignature.getColumnNames()), new HashMap<>(), new HashMap<>() ); @@ -117,11 +116,8 @@ public class VirtualColumnRegistry */ public RowSignature getFullRowSignature() { - final RowSignature.Builder builder = RowSignature.builder(); - - for (String columnName : baseRowSignature.getRowOrder()) { - builder.add(columnName, baseRowSignature.getColumnType(columnName)); - } + final RowSignature.Builder builder = + RowSignature.builder().addAll(baseRowSignature); for (VirtualColumn virtualColumn : virtualColumnsByName.values()) { final String columnName = virtualColumn.getOutputName(); diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/rule/GroupByRules.java b/sql/src/main/java/org/apache/druid/sql/calcite/rule/GroupByRules.java index 22098545e9c..2489ed7a538 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/rule/GroupByRules.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/rule/GroupByRules.java @@ -26,13 +26,13 @@ import org.apache.calcite.rex.RexNode; import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.FilteredAggregatorFactory; import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.aggregation.Aggregation; import org.apache.druid.sql.calcite.aggregation.SqlAggregator; import org.apache.druid.sql.calcite.expression.Expressions; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; -import org.apache.druid.sql.calcite.table.RowSignature; import java.util.ArrayList; import java.util.List; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/AvailableSegmentMetadata.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/AvailableSegmentMetadata.java index 4efff1130f1..20d9b7e0ad9 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/AvailableSegmentMetadata.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/AvailableSegmentMetadata.java @@ -19,8 +19,8 @@ package org.apache.druid.sql.calcite.schema; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.server.coordination.DruidServerMetadata; -import org.apache.druid.sql.calcite.table.RowSignature; import org.apache.druid.timeline.DataSegment; import javax.annotation.Nullable; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java index a0733269128..9f087eaf9cc 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/DruidSchema.java @@ -53,6 +53,7 @@ import org.apache.druid.query.metadata.metadata.ColumnAnalysis; import org.apache.druid.query.metadata.metadata.SegmentAnalysis; import org.apache.druid.query.metadata.metadata.SegmentMetadataQuery; import org.apache.druid.query.spec.MultipleSpecificSegmentSpec; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.server.QueryLifecycleFactory; import org.apache.druid.server.coordination.DruidServerMetadata; @@ -61,7 +62,6 @@ import org.apache.druid.server.security.AuthenticationResult; import org.apache.druid.server.security.Escalator; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.table.DruidTable; -import org.apache.druid.sql.calcite.table.RowSignature; import org.apache.druid.sql.calcite.view.DruidViewMacro; import org.apache.druid.sql.calcite.view.ViewManager; import org.apache.druid.timeline.DataSegment; @@ -592,9 +592,13 @@ public class DruidSchema extends AbstractSchema for (AvailableSegmentMetadata availableSegmentMetadata : segmentMap.values()) { final RowSignature rowSignature = availableSegmentMetadata.getRowSignature(); if (rowSignature != null) { - for (String column : rowSignature.getRowOrder()) { + for (String column : rowSignature.getColumnNames()) { // Newer column types should override older ones. - columnTypes.putIfAbsent(column, rowSignature.getColumnType(column)); + final ValueType columnType = + rowSignature.getColumnType(column) + .orElseThrow(() -> new ISE("Encountered null type for column[%s]", column)); + + columnTypes.putIfAbsent(column, columnType); } } } diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/InformationSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/InformationSchema.java index 1b96922d828..bf84ea131c8 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/InformationSchema.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/InformationSchema.java @@ -46,13 +46,14 @@ import org.apache.calcite.schema.TableMacro; import org.apache.calcite.schema.impl.AbstractSchema; import org.apache.calcite.schema.impl.AbstractTable; import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.server.security.AuthenticationResult; import org.apache.druid.server.security.AuthorizationUtils; import org.apache.druid.server.security.AuthorizerMapper; import org.apache.druid.server.security.ResourceAction; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import javax.annotation.Nullable; import java.util.Collection; @@ -169,7 +170,7 @@ public class InformationSchema extends AbstractSchema @Override public RelDataType getRowType(final RelDataTypeFactory typeFactory) { - return SCHEMATA_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(SCHEMATA_SIGNATURE, typeFactory); } @Override @@ -262,7 +263,7 @@ public class InformationSchema extends AbstractSchema @Override public RelDataType getRowType(final RelDataTypeFactory typeFactory) { - return TABLES_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(TABLES_SIGNATURE, typeFactory); } @Override @@ -359,7 +360,7 @@ public class InformationSchema extends AbstractSchema @Override public RelDataType getRowType(final RelDataTypeFactory typeFactory) { - return COLUMNS_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(COLUMNS_SIGNATURE, typeFactory); } @Override diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/LookupSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/LookupSchema.java index ef64e061b20..b3f33147179 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/LookupSchema.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/LookupSchema.java @@ -25,10 +25,10 @@ import org.apache.calcite.schema.Table; import org.apache.calcite.schema.impl.AbstractSchema; import org.apache.druid.query.LookupDataSource; import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.join.lookup.LookupColumnSelectorFactory; import org.apache.druid.sql.calcite.table.DruidTable; -import org.apache.druid.sql.calcite.table.RowSignature; import java.util.Map; diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java b/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java index 6ecbca6654b..c6bff43ac07 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java @@ -60,6 +60,7 @@ import org.apache.druid.java.util.common.RE; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.parsers.CloseableIterator; import org.apache.druid.java.util.http.client.Request; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.server.DruidNode; import org.apache.druid.server.coordinator.BytesAccumulatingResponseHandler; @@ -72,7 +73,7 @@ import org.apache.druid.server.security.ForbiddenException; import org.apache.druid.server.security.Resource; import org.apache.druid.server.security.ResourceAction; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.SegmentId; import org.apache.druid.timeline.SegmentWithOvershadowedStatus; @@ -257,7 +258,7 @@ public class SystemSchema extends AbstractSchema @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { - return SEGMENTS_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(SEGMENTS_SIGNATURE, typeFactory); } @Override @@ -478,7 +479,7 @@ public class SystemSchema extends AbstractSchema @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { - return SERVERS_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(SERVERS_SIGNATURE, typeFactory); } @Override @@ -547,7 +548,7 @@ public class SystemSchema extends AbstractSchema @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { - return SERVER_SEGMENTS_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(SERVER_SEGMENTS_SIGNATURE, typeFactory); } @Override @@ -566,7 +567,7 @@ public class SystemSchema extends AbstractSchema final List rows = new ArrayList<>(); final List druidServers = serverView.getDruidServers(); - final int serverSegmentsTableSize = SERVER_SEGMENTS_SIGNATURE.getRowOrder().size(); + final int serverSegmentsTableSize = SERVER_SEGMENTS_SIGNATURE.size(); for (ImmutableDruidServer druidServer : druidServers) { final Iterable authorizedServerSegments = AuthorizationUtils.filterAuthorizedResources( authenticationResult, @@ -612,7 +613,7 @@ public class SystemSchema extends AbstractSchema @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { - return TASKS_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(TASKS_SIGNATURE, typeFactory); } @Override @@ -796,7 +797,7 @@ public class SystemSchema extends AbstractSchema @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { - return SUPERVISOR_SIGNATURE.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(SUPERVISOR_SIGNATURE, typeFactory); } @Override diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/table/DruidTable.java b/sql/src/main/java/org/apache/druid/sql/calcite/table/DruidTable.java index e12b10b62a5..521a051b7c9 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/table/DruidTable.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/table/DruidTable.java @@ -33,6 +33,7 @@ import org.apache.calcite.schema.TranslatableTable; import org.apache.calcite.sql.SqlCall; import org.apache.calcite.sql.SqlNode; import org.apache.druid.query.DataSource; +import org.apache.druid.segment.column.RowSignature; import java.util.Objects; @@ -75,7 +76,7 @@ public class DruidTable implements TranslatableTable @Override public RelDataType getRowType(final RelDataTypeFactory typeFactory) { - return rowSignature.getRelDataType(typeFactory); + return RowSignatures.toRelDataType(rowSignature, typeFactory); } @Override diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/table/RowSignature.java b/sql/src/main/java/org/apache/druid/sql/calcite/table/RowSignatures.java similarity index 50% rename from sql/src/main/java/org/apache/druid/sql/calcite/table/RowSignature.java rename to sql/src/main/java/org/apache/druid/sql/calcite/table/RowSignatures.java index ebce93d6925..97d6ed9b3d5 100644 --- a/sql/src/main/java/org/apache/druid/sql/calcite/table/RowSignature.java +++ b/sql/src/main/java/org/apache/druid/sql/calcite/table/RowSignatures.java @@ -20,8 +20,6 @@ package org.apache.druid.sql.calcite.table; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeFactory; import org.apache.calcite.rel.type.RelDataTypeField; @@ -29,58 +27,34 @@ import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.common.config.NullHandling; import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.ISE; -import org.apache.druid.java.util.common.Pair; import org.apache.druid.query.ordering.StringComparator; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.SimpleExtraction; import org.apache.druid.sql.calcite.planner.Calcites; import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Objects; /** - * Type signature for a row in a Druid dataSource ("DruidTable") or query result. Rows have an ordering and every - * column has a defined type. This is a little bit of a fiction in the Druid world (where rows do not _actually_ have - * well defined types) but we do impose types for the SQL layer. + * Utility functions for working with {@link RowSignature}. */ -public class RowSignature +public class RowSignatures { - private final Map columnTypes; - private final List columnNames; - - private RowSignature(final List> columnTypeList) + private RowSignatures() { - final Map columnTypes0 = new HashMap<>(); - final ImmutableList.Builder columnNamesBuilder = ImmutableList.builder(); - - int i = 0; - for (Pair pair : columnTypeList) { - final ValueType existingType = columnTypes0.get(pair.lhs); - if (existingType != null && existingType != pair.rhs) { - throw new IAE("Column[%s] has conflicting types [%s] and [%s]", pair.lhs, existingType, pair.rhs); - } - - columnTypes0.put(pair.lhs, pair.rhs); - columnNamesBuilder.add(pair.lhs); - } - - this.columnTypes = ImmutableMap.copyOf(columnTypes0); - this.columnNames = columnNamesBuilder.build(); + // No instantiation. } - public static RowSignature from(final List rowOrder, final RelDataType rowType) + public static RowSignature fromRelDataType(final List rowOrder, final RelDataType rowType) { if (rowOrder.size() != rowType.getFieldCount()) { throw new IAE("Field count %d != %d", rowOrder.size(), rowType.getFieldCount()); } - final RowSignature.Builder rowSignatureBuilder = builder(); + final RowSignature.Builder rowSignatureBuilder = RowSignature.builder(); for (int i = 0; i < rowOrder.size(); i++) { final RelDataTypeField field = rowType.getFieldList().get(i); @@ -98,40 +72,19 @@ public class RowSignature return rowSignatureBuilder.build(); } - public static Builder builder() - { - return new Builder(); - } - - public ValueType getColumnType(final String name) - { - return columnTypes.get(name); - } - /** - * Returns the rowOrder for this signature, which is the list of column names in row order. - * - * @return row order - */ - public List getRowOrder() - { - return columnNames; - } - - /** - * Return the "natural" {@link StringComparator} for an extraction from this row signature. This will be a + * Return the "natural" {@link StringComparator} for an extraction from a row signature. This will be a * lexicographic comparator for String types and a numeric comparator for Number types. - * - * @param simpleExtraction extraction from this kind of row - * - * @return natural comparator */ @Nonnull - public StringComparator naturalStringComparator(final SimpleExtraction simpleExtraction) + public static StringComparator getNaturalStringComparator( + final RowSignature rowSignature, + final SimpleExtraction simpleExtraction + ) { Preconditions.checkNotNull(simpleExtraction, "simpleExtraction"); if (simpleExtraction.getExtractionFn() != null - || getColumnType(simpleExtraction.getColumn()) == ValueType.STRING) { + || rowSignature.getColumnType(simpleExtraction.getColumn()).orElse(null) == ValueType.STRING) { return StringComparators.LEXICOGRAPHIC; } else { return StringComparators.NUMERIC; @@ -139,23 +92,22 @@ public class RowSignature } /** - * Returns a Calcite RelDataType corresponding to this row signature. - * - * @param typeFactory factory for type construction - * - * @return Calcite row type + * Returns a Calcite RelDataType corresponding to a row signature. */ - public RelDataType getRelDataType(final RelDataTypeFactory typeFactory) + public static RelDataType toRelDataType(final RowSignature rowSignature, final RelDataTypeFactory typeFactory) { final RelDataTypeFactory.Builder builder = typeFactory.builder(); final boolean nullNumeric = !NullHandling.replaceWithDefault(); - for (final String columnName : columnNames) { - final ValueType columnType = getColumnType(columnName); + for (final String columnName : rowSignature.getColumnNames()) { final RelDataType type; if (ColumnHolder.TIME_COLUMN_NAME.equals(columnName)) { type = Calcites.createSqlType(typeFactory, SqlTypeName.TIMESTAMP); } else { + final ValueType columnType = + rowSignature.getColumnType(columnName) + .orElseThrow(() -> new ISE("Encountered null type for column[%s]", columnName)); + switch (columnType) { case STRING: // Note that there is no attempt here to handle multi-value in any special way. Maybe one day... @@ -175,7 +127,7 @@ public class RowSignature type = Calcites.createSqlTypeWithNullability(typeFactory, SqlTypeName.OTHER, true); break; default: - throw new ISE("WTF?! valueType[%s] not translatable?", columnType); + throw new ISE("valueType[%s] not translatable", columnType); } } @@ -184,68 +136,4 @@ public class RowSignature return builder.build(); } - - @Override - public boolean equals(Object o) - { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - RowSignature that = (RowSignature) o; - - if (!Objects.equals(columnTypes, that.columnTypes)) { - return false; - } - return Objects.equals(columnNames, that.columnNames); - } - - @Override - public int hashCode() - { - int result = columnTypes != null ? columnTypes.hashCode() : 0; - result = 31 * result + (columnNames != null ? columnNames.hashCode() : 0); - return result; - } - - @Override - public String toString() - { - final StringBuilder s = new StringBuilder("{"); - for (int i = 0; i < columnNames.size(); i++) { - if (i > 0) { - s.append(", "); - } - final String columnName = columnNames.get(i); - s.append(columnName).append(":").append(getColumnType(columnName)); - } - return s.append("}").toString(); - } - - public static class Builder - { - private final List> columnTypeList; - - private Builder() - { - this.columnTypeList = new ArrayList<>(); - } - - public Builder add(String columnName, ValueType columnType) - { - Preconditions.checkNotNull(columnName, "columnName"); - Preconditions.checkNotNull(columnType, "columnType"); - - columnTypeList.add(Pair.of(columnName, columnType)); - return this; - } - - public RowSignature build() - { - return new RowSignature(columnTypeList); - } - } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionTestHelper.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionTestHelper.java index 6fffe8028d8..48dea514481 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionTestHelper.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionTestHelper.java @@ -32,10 +32,11 @@ import org.apache.calcite.sql.SqlOperator; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.math.expr.ExprEval; import org.apache.druid.math.expr.Parser; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import org.apache.druid.sql.calcite.util.CalciteTests; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -73,7 +74,7 @@ class ExpressionTestHelper this.typeFactory = new JavaTypeFactoryImpl(); this.rexBuilder = new RexBuilder(typeFactory); - this.relDataType = rowSignature.getRelDataType(typeFactory); + this.relDataType = RowSignatures.toRelDataType(rowSignature, typeFactory); } RelDataType createSqlType(SqlTypeName sqlTypeName) @@ -83,7 +84,7 @@ class ExpressionTestHelper RexNode makeInputRef(String columnName) { - int columnNumber = rowSignature.getRowOrder().indexOf(columnName); + int columnNumber = rowSignature.indexOf(columnName); return rexBuilder.makeInputRef(relDataType.getFieldList().get(columnNumber).getType(), columnNumber); } @@ -232,7 +233,7 @@ class ExpressionTestHelper Assert.assertEquals("Expression for: " + rexNode, expectedExpression, expression); ExprEval result = Parser.parse(expression.getExpression(), PLANNER_CONTEXT.getExprMacroTable()) - .eval(Parser.withMap(bindings)); + .eval(Parser.withMap(bindings)); Assert.assertEquals("Result for: " + rexNode, expectedResult, result.value()); } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java index 35267c843f7..d2370d793e9 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java @@ -33,6 +33,7 @@ import org.apache.druid.common.config.NullHandling; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.IAE; import org.apache.druid.query.extraction.RegexDimExtractionFn; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.builtin.DateTruncOperatorConversion; import org.apache.druid.sql.calcite.expression.builtin.LPadOperatorConversion; @@ -53,7 +54,6 @@ import org.apache.druid.sql.calcite.expression.builtin.TimeFormatOperatorConvers import org.apache.druid.sql.calcite.expression.builtin.TimeParseOperatorConversion; import org.apache.druid.sql.calcite.expression.builtin.TimeShiftOperatorConversion; import org.apache.druid.sql.calcite.expression.builtin.TruncateOperatorConversion; -import org.apache.druid.sql.calcite.table.RowSignature; import org.joda.time.Period; import org.junit.Before; import org.junit.Test; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java index 0d0aeb4edad..9318028d917 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java @@ -21,9 +21,9 @@ package org.apache.druid.sql.calcite.expression; import com.google.common.collect.ImmutableMap; import org.apache.calcite.rex.RexNode; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.builtin.IPv4AddressMatchOperatorConversion; -import org.apache.druid.sql.calcite.table.RowSignature; import org.junit.Before; import org.junit.Test; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java index c3c7169c213..3d8956c52e7 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java @@ -22,9 +22,9 @@ package org.apache.druid.sql.calcite.expression; import com.google.common.collect.ImmutableMap; import org.apache.calcite.rex.RexNode; import org.apache.druid.common.config.NullHandling; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.builtin.IPv4AddressParseOperatorConversion; -import org.apache.druid.sql.calcite.table.RowSignature; import org.junit.Before; import org.junit.Test; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java index e34a55915a1..5a0a50e7d85 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java @@ -21,9 +21,9 @@ package org.apache.druid.sql.calcite.expression; import com.google.common.collect.ImmutableMap; import org.apache.calcite.rex.RexNode; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.sql.calcite.expression.builtin.IPv4AddressStringifyOperatorConversion; -import org.apache.druid.sql.calcite.table.RowSignature; import org.junit.Before; import org.junit.Test; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java index d8f6f6f2f68..7bfae93fcc5 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java @@ -24,8 +24,8 @@ import org.apache.druid.java.util.common.Intervals; import org.apache.druid.query.filter.IntervalDimFilter; import org.apache.druid.query.filter.NotDimFilter; import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; -import org.apache.druid.sql.calcite.table.RowSignature; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.junit.Assert; import org.junit.Test; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java index 8e9d6d90756..1b5fb5c3fb5 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java @@ -48,6 +48,7 @@ import org.apache.druid.discovery.DruidNodeDiscovery; import org.apache.druid.discovery.DruidNodeDiscoveryProvider; import org.apache.druid.discovery.NodeRole; import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.Pair; import org.apache.druid.java.util.common.StringUtils; @@ -64,6 +65,7 @@ import org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFact import org.apache.druid.segment.IndexBuilder; import org.apache.druid.segment.QueryableIndex; import org.apache.druid.segment.TestHelper; +import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.writeout.OffHeapMemorySegmentWriteOutMediumFactory; @@ -76,7 +78,7 @@ import org.apache.druid.server.security.Authorizer; import org.apache.druid.server.security.AuthorizerMapper; import org.apache.druid.server.security.NoopEscalator; import org.apache.druid.sql.calcite.planner.PlannerConfig; -import org.apache.druid.sql.calcite.table.RowSignature; +import org.apache.druid.sql.calcite.table.RowSignatures; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.SpecificSegmentsQuerySegmentWalker; @@ -662,7 +664,8 @@ public class SystemSchemaTest extends CalciteTestBase long isPublished, long isAvailable, long isRealtime, - long isOvershadowed) + long isOvershadowed + ) { Assert.assertEquals(segmentId, row[0].toString()); SegmentId id = Iterables.get(SegmentId.iterateAllPossibleParsings(segmentId), 0); @@ -731,10 +734,14 @@ public class SystemSchemaTest extends CalciteTestBase EasyMock.expect(indexerNodeDiscovery.getAllNodes()).andReturn(ImmutableList.of(indexer)).once(); final DruidServer server1 = EasyMock.createMock(DruidServer.class); - EasyMock.expect(serverInventoryView.getInventoryValue(historical1.toDruidServer().getName())).andReturn(server1).once(); + EasyMock.expect(serverInventoryView.getInventoryValue(historical1.toDruidServer().getName())) + .andReturn(server1) + .once(); EasyMock.expect(server1.getCurrSize()).andReturn(200L).once(); final DruidServer server2 = EasyMock.createMock(DruidServer.class); - EasyMock.expect(serverInventoryView.getInventoryValue(historical2.toDruidServer().getName())).andReturn(server2).once(); + EasyMock.expect(serverInventoryView.getInventoryValue(historical2.toDruidServer().getName())) + .andReturn(server2) + .once(); EasyMock.expect(server2.getCurrSize()).andReturn(400L).once(); EasyMock.replay(druidNodeDiscoveryProvider, serverInventoryView, server1, server2); @@ -913,7 +920,8 @@ public class SystemSchemaTest extends CalciteTestBase String serverType, String tier, long currSize, - long maxSize) + long maxSize + ) { Assert.assertEquals(server, row[0].toString()); Assert.assertEquals(host, row[1]); @@ -1124,7 +1132,12 @@ public class SystemSchemaTest extends CalciteTestBase { SystemSchema.SupervisorsTable supervisorTable = EasyMock.createMockBuilder(SystemSchema.SupervisorsTable.class) - .withConstructor(client, mapper, responseHandler, authMapper) + .withConstructor( + client, + mapper, + responseHandler, + authMapper + ) .createMock(); EasyMock.replay(supervisorTable); EasyMock.expect(client.makeRequest(HttpMethod.GET, "/druid/indexer/v1/supervisor?system", false)) @@ -1205,15 +1218,18 @@ public class SystemSchemaTest extends CalciteTestBase private static void verifyTypes(final List rows, final RowSignature signature) { - final RelDataType rowType = signature.getRelDataType(new JavaTypeFactoryImpl()); + final RelDataType rowType = RowSignatures.toRelDataType(signature, new JavaTypeFactoryImpl()); for (Object[] row : rows) { - Assert.assertEquals(row.length, signature.getRowOrder().size()); + Assert.assertEquals(row.length, signature.size()); for (int i = 0; i < row.length; i++) { final Class expectedClass; - final ValueType columnType = signature.getColumnType(signature.getRowOrder().get(i)); + final ValueType columnType = + signature.getColumnType(i) + .orElseThrow(() -> new ISE("Encountered null column type")); + final boolean nullable = rowType.getFieldList().get(i).getType().isNullable(); switch (columnType) { @@ -1227,7 +1243,7 @@ public class SystemSchemaTest extends CalciteTestBase expectedClass = Double.class; break; case STRING: - if (signature.getRowOrder().get(i).equals("segment_id")) { + if (signature.getColumnName(i).equals("segment_id")) { expectedClass = SegmentId.class; } else { expectedClass = String.class; @@ -1241,7 +1257,7 @@ public class SystemSchemaTest extends CalciteTestBase Assert.assertTrue( StringUtils.format( "Column[%s] is a [%s] or null (was %s)", - signature.getRowOrder().get(i), + signature.getColumnName(i), expectedClass.getName(), row[i] == null ? null : row[i].getClass().getName() ), @@ -1251,7 +1267,7 @@ public class SystemSchemaTest extends CalciteTestBase Assert.assertTrue( StringUtils.format( "Column[%s] is a [%s] (was %s)", - signature.getRowOrder().get(i), + signature.getColumnName(i), expectedClass.getName(), row[i] == null ? null : row[i].getClass().getName() ),