Skip to content

Commit

Permalink
[CALCITE-6684] Arrow adapter should supports filter conditions of Dec…
Browse files Browse the repository at this point in the history
…imal type
  • Loading branch information
caicancai committed Nov 10, 2024
1 parent aced08d commit 03ddf0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ private static TreeNode makeLiteralNode(String literal, String type) {
return TreeBuilder.makeLiteral(parseFloat(literal));
case "double":
return TreeBuilder.makeLiteral(parseDouble(literal));
case "decimal":
return TreeBuilder.makeDecimalLiteral(literal, 19, 0);
case "string":
return TreeBuilder.makeStringLiteral(literal.substring(1, literal.length() - 1));
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private String translateBinary(String op, String rop, RexCall call) {
private String translateOp2(String op, String name, RexLiteral right) {
Object value = literalValue(right);
String valueString = value.toString();
String valueType = getLiteralType(value);
String valueType = getLiteralType(value, right.getType());

if (value instanceof String) {
final RelDataTypeField field = requireNonNull(rowType.getField(name, true, false), "field");
Expand Down Expand Up @@ -234,8 +234,10 @@ private String translateUnaryOp(String op, String name) {
return name + " " + op;
}

private static String getLiteralType(Object literal) {
if (literal instanceof BigDecimal) {
private static String getLiteralType(Object literal, RelDataType type) {
if (type.getSqlTypeName() == SqlTypeName.DECIMAL) {
return "decimal";
} else if (literal instanceof BigDecimal) {
BigDecimal bigDecimalLiteral = (BigDecimal) literal;
int scale = bigDecimalLiteral.scale();
if (scale == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,4 +943,21 @@ static void initializeArrowState(@TempDir Path sharedTempDir)
.returns(result)
.explainContains(plan);
}

@Test void testArrowProjectFieldsWithDecimalFilter() {
String sql = "select \"decimalField\"\n"
+ "from arrowdatatype\n"
+ "where \"decimalField\" = 1.00";
String plan = "PLAN=ArrowToEnumerableConverter\n"
+ " ArrowProject(decimalField=[$8])\n"
+ " ArrowFilter(condition=[=($8, 1)])\n"
+ " ArrowTableScan(table=[[ARROW, ARROWDATATYPE]], fields=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])\n\n";
String result = "decimalField=1.00\n";

CalciteAssert.that()
.with(arrow)
.query(sql)
.returns(result)
.explainContains(plan);
}
}

0 comments on commit 03ddf0c

Please sign in to comment.