-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL version of unnest native druid function #13576
Changes from 15 commits
2e72fd3
812133f
80846d3
828bf95
2a308be
cce6aa8
f0ac1a3
6385f16
92e161a
6767913
de943e9
ff561dd
fbb5d5b
f820307
94f47a5
3afd027
6356ba3
8a854dc
4f99571
0376170
a1e0ea8
06b3811
8c03d38
2bb22fa
df05cf4
533be68
16c750c
bf0e27c
301cbaa
5320349
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,7 +181,10 @@ public void inspectRuntimeShape(RuntimeShapeInspector inspector) | |
@Override | ||
public Object getObject() | ||
{ | ||
if (indexedIntsForCurrentRow == null) { | ||
if (dimSelector.getObject() == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we switch away from using the stored reference? It looks to me like you just needed to switch it to be
And then, you could perhaps make it even simpler if you check the size once when setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving to stored reference and setting the |
||
return null; | ||
} | ||
if (indexedIntsForCurrentRow.size() == 0) { | ||
return null; | ||
} | ||
if (allowedBitSet.isEmpty()) { | ||
|
@@ -409,7 +412,12 @@ public int size() | |
@Override | ||
public int get(int idx) | ||
{ | ||
return indexedIntsForCurrentRow.get(index); | ||
// to support rows which have only null values | ||
// need to check if rhe value is not null and the size is greater than 0 | ||
if (indexedIntsForCurrentRow != null && indexedIntsForCurrentRow.size() > 0) { | ||
return indexedIntsForCurrentRow.get(index); | ||
} | ||
return 0; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import org.apache.calcite.jdbc.JavaTypeFactoryImpl; | ||
import org.apache.calcite.rel.core.Project; | ||
import org.apache.calcite.rex.RexCall; | ||
import org.apache.calcite.rex.RexFieldAccess; | ||
import org.apache.calcite.rex.RexInputRef; | ||
import org.apache.calcite.rex.RexLiteral; | ||
import org.apache.calcite.rex.RexNode; | ||
|
@@ -34,6 +35,7 @@ | |
import org.apache.druid.common.config.NullHandling; | ||
import org.apache.druid.java.util.common.DateTimes; | ||
import org.apache.druid.java.util.common.ISE; | ||
import org.apache.druid.java.util.common.StringUtils; | ||
import org.apache.druid.java.util.common.granularity.Granularity; | ||
import org.apache.druid.math.expr.Expr; | ||
import org.apache.druid.math.expr.ExprMacroTable; | ||
|
@@ -58,6 +60,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.CannotBuildQueryException; | ||
import org.apache.druid.sql.calcite.rel.VirtualColumnRegistry; | ||
import org.apache.druid.sql.calcite.table.RowSignatures; | ||
import org.joda.time.Interval; | ||
|
@@ -214,12 +217,43 @@ public static DruidExpression toDruidExpressionWithPostAggOperands( | |
return rexCallToDruidExpression(plannerContext, rowSignature, rexNode, postAggregatorVisitor); | ||
} else if (kind == SqlKind.LITERAL) { | ||
return literalToDruidExpression(plannerContext, rexNode); | ||
} else if (kind == SqlKind.FIELD_ACCESS) { | ||
return fieldAccessToDruidExpression(rowSignature, rexNode); | ||
} else { | ||
// Can't translate. | ||
return null; | ||
} | ||
} | ||
|
||
private static DruidExpression fieldAccessToDruidExpression( | ||
final RowSignature rowSignature, | ||
final RexNode rexNode | ||
) | ||
{ | ||
// Translate field references. | ||
final RexFieldAccess ref = (RexFieldAccess) rexNode; | ||
// This case arises in the case of a correlation where the rexNode points to a table from the left subtree | ||
// while the underlying datasource is the scan stub created from LogicalValuesRule | ||
// In such a case we throw a CannotBuildQueryException so that Calcite does not go ahead with this path | ||
// This exception is caught while returning false from isValidDruidQuery() method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this comment has been separated from its home. Is it inside of the if down below? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this to inside of the if |
||
|
||
//use this index to return | ||
final int index = rowSignature.getColumnNames().indexOf(ref.getField().getName()); | ||
if (ref.getField().getIndex() > rowSignature.size()) { | ||
throw new CannotBuildQueryException(StringUtils.format( | ||
"Cannot build query as column name [%s] does not exist in row [%s]", ref.getField().getName(), rowSignature) | ||
); | ||
} | ||
|
||
final String columnName = rowSignature.getColumnName(index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't we just search the rowSignature for the name? Why will we get a different name back than the one that we searched for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We used the rexNodes name to find the index before. Now we are just using the column name of the row signature at the particular index |
||
final Optional<ColumnType> columnType = rowSignature.getColumnType(index); | ||
if (columnName == null) { | ||
throw new ISE("Expression referred to nonexistent index [%d] in row [%s]", index, rowSignature); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe this if block can ever be run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True we are ensuring the index is always within the rowSignature length, will remove this |
||
|
||
return DruidExpression.ofColumn(columnType.orElse(null), columnName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would we ever not have the columnType? Why do we need to orElse it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the index in bounds this should be just |
||
} | ||
|
||
private static DruidExpression inputRefToDruidExpression( | ||
final RowSignature rowSignature, | ||
final RexNode rexNode | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a
hashCode
method that claims that it is compatible with this method. I'm not sure that is actually true anymore because I don't believe it walks into Arrays-of-Arrays the same way that this one does.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change got percolated here, I'll move to the
equals
here