Jackie-Jiang commented on code in PR #11478:
URL: https://github.com/apache/pinot/pull/11478#discussion_r1312762348


##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/FloatingPointDataTypeTest.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.pinot.integration.tests.custom;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.ImmutableList;
+import java.io.File;
+import java.io.IOException;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+/**
+ * Integration test for floating point data type (float & double) filter 
queries.
+ */
+@Test(suiteName = "CustomClusterIntegrationTest")
+public class FloatingPointDataTypeTest extends 
CustomDataQueryClusterIntegrationTest {
+  private static final String DEFAULT_TABLE_NAME = "FloatingPointDataTypeTest";
+  private static final int NUM_DOCS = 10;
+  private static final String MET_DOUBLE = "metDouble";
+  private static final String MET_FLOAT = "metFloat";
+
+  @Override
+  public String getTableName() {
+    return DEFAULT_TABLE_NAME;
+  }
+
+  @Override
+  public Schema createSchema() {
+    return new Schema.SchemaBuilder().setSchemaName(getTableName())
+        .addMetric(MET_DOUBLE, FieldSpec.DataType.DOUBLE)
+        .addMetric(MET_FLOAT, FieldSpec.DataType.FLOAT)
+        .build();
+  }
+
+  @Override
+  public File createAvroFile()
+      throws IOException {
+
+    // create avro schema
+    org.apache.avro.Schema avroSchema = 
org.apache.avro.Schema.createRecord("myRecord", null, null, false);
+    avroSchema.setFields(ImmutableList.of(
+        new org.apache.avro.Schema.Field(MET_DOUBLE, 
org.apache.avro.Schema.create(org.apache.avro.Schema.Type.DOUBLE),
+            null, null),
+        new org.apache.avro.Schema.Field(MET_FLOAT, 
org.apache.avro.Schema.create(org.apache.avro.Schema.Type.FLOAT),
+            null, null)));
+
+    // create avro file
+    File avroFile = new File(_tempDir, "data.avro");
+    try (DataFileWriter<GenericData.Record> fileWriter = new 
DataFileWriter<>(new GenericDatumWriter<>(avroSchema))) {
+      fileWriter.create(avroSchema, avroFile);
+      double doubleValue = 0.0;
+      float floatValue = 0.0f;
+      for (int i = 0; i < getCountStarResult(); i++) {
+        // create avro record
+        GenericData.Record record = new GenericData.Record(avroSchema);
+        record.put(MET_DOUBLE, doubleValue);
+        record.put(MET_FLOAT, floatValue);
+        doubleValue += 0.01;
+        floatValue += 0.01f;
+
+        // add avro record to file
+        fileWriter.append(record);
+      }
+    }
+    return avroFile;
+  }
+
+  @Override
+  protected long getCountStarResult() {
+    return NUM_DOCS;
+  }
+
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testQueries(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+    String[][] filterAndExpectedCount = {
+        {MET_DOUBLE + " > 0.05", "4"}, {MET_DOUBLE + " = 0.05", "1"}, 
{MET_DOUBLE + " < 0.05", "5"},

Review Comment:
   Will this trigger the code path? Does it require the literal to be double?



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/FloatingPointDataTypeTest.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.pinot.integration.tests.custom;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.ImmutableList;
+import java.io.File;
+import java.io.IOException;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+/**
+ * Integration test for floating point data type (float & double) filter 
queries.
+ */
+@Test(suiteName = "CustomClusterIntegrationTest")
+public class FloatingPointDataTypeTest extends 
CustomDataQueryClusterIntegrationTest {
+  private static final String DEFAULT_TABLE_NAME = "FloatingPointDataTypeTest";
+  private static final int NUM_DOCS = 10;
+  private static final String MET_DOUBLE = "metDouble";
+  private static final String MET_FLOAT = "metFloat";
+
+  @Override
+  public String getTableName() {
+    return DEFAULT_TABLE_NAME;
+  }
+
+  @Override
+  public Schema createSchema() {
+    return new Schema.SchemaBuilder().setSchemaName(getTableName())
+        .addMetric(MET_DOUBLE, FieldSpec.DataType.DOUBLE)
+        .addMetric(MET_FLOAT, FieldSpec.DataType.FLOAT)
+        .build();
+  }
+
+  @Override
+  public File createAvroFile()
+      throws IOException {
+
+    // create avro schema
+    org.apache.avro.Schema avroSchema = 
org.apache.avro.Schema.createRecord("myRecord", null, null, false);
+    avroSchema.setFields(ImmutableList.of(
+        new org.apache.avro.Schema.Field(MET_DOUBLE, 
org.apache.avro.Schema.create(org.apache.avro.Schema.Type.DOUBLE),
+            null, null),
+        new org.apache.avro.Schema.Field(MET_FLOAT, 
org.apache.avro.Schema.create(org.apache.avro.Schema.Type.FLOAT),
+            null, null)));
+
+    // create avro file
+    File avroFile = new File(_tempDir, "data.avro");
+    try (DataFileWriter<GenericData.Record> fileWriter = new 
DataFileWriter<>(new GenericDatumWriter<>(avroSchema))) {
+      fileWriter.create(avroSchema, avroFile);
+      double doubleValue = 0.0;
+      float floatValue = 0.0f;
+      for (int i = 0; i < getCountStarResult(); i++) {
+        // create avro record
+        GenericData.Record record = new GenericData.Record(avroSchema);
+        record.put(MET_DOUBLE, doubleValue);
+        record.put(MET_FLOAT, floatValue);
+        doubleValue += 0.01;
+        floatValue += 0.01f;
+
+        // add avro record to file
+        fileWriter.append(record);
+      }
+    }
+    return avroFile;
+  }
+
+  @Override
+  protected long getCountStarResult() {
+    return NUM_DOCS;
+  }
+
+  @Test(dataProvider = "useBothQueryEngines")
+  public void testQueries(boolean useMultiStageQueryEngine)
+      throws Exception {
+    setUseMultiStageQueryEngine(useMultiStageQueryEngine);
+    String[][] filterAndExpectedCount = {
+        {MET_DOUBLE + " > 0.05", "4"}, {MET_DOUBLE + " = 0.05", "1"}, 
{MET_DOUBLE + " < 0.05", "5"},
+        {MET_FLOAT + " > 0.05", "4"}
+        // FIXME: the result of the following queries is not correct
+        //  , {MET_FLOAT + " = 0.05", "1"}, {MET_FLOAT + " < 0.05", "5"}

Review Comment:
   Any idea why this does not work?



##########
pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/NumericalFilterOptimizer.java:
##########
@@ -334,14 +334,12 @@ private static Expression 
rewriteRangeExpression(Expression range, FilterKind ki
               // Literal value is less than the bounds of LONG.
               return getExpressionFromBoolean(
                   kind == FilterKind.GREATER_THAN || kind == 
FilterKind.GREATER_THAN_OR_EQUAL);
-            } else {
-              int comparison = Double.compare(actual, converted);
-              // Rewrite range operator
-              rewriteRangeOperator(range, kind, comparison);
-
-              // Rewrite range literal
-              rhs.getLiteral().setDoubleValue(converted);
             }
+            // Do not rewrite range operator since double has higher precision 
than float
+            // If we do, we may introduce problems.
+            // For example, in the previous logic, "> 0.5" will be converted 
into ">= 0.05000000074505806". When the

Review Comment:
   (typo)
   ```suggestion
               // For example, in the previous logic, "> 0.5" will be converted 
into ">= 0.5000000074505806". When the
   ```



##########
pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/FloatingPointDataTypeTest.java:
##########
@@ -0,0 +1,114 @@
+/**
+ * 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.pinot.integration.tests.custom;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.ImmutableList;
+import java.io.File;
+import java.io.IOException;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+/**
+ * Integration test for floating point data type (float & double) filter 
queries.
+ */
+@Test(suiteName = "CustomClusterIntegrationTest")
+public class FloatingPointDataTypeTest extends 
CustomDataQueryClusterIntegrationTest {
+  private static final String DEFAULT_TABLE_NAME = "FloatingPointDataTypeTest";
+  private static final int NUM_DOCS = 10;
+  private static final String MET_DOUBLE = "metDouble";
+  private static final String MET_FLOAT = "metFloat";
+
+  @Override
+  public String getTableName() {
+    return DEFAULT_TABLE_NAME;
+  }
+
+  @Override
+  public Schema createSchema() {
+    return new Schema.SchemaBuilder().setSchemaName(getTableName())
+        .addMetric(MET_DOUBLE, FieldSpec.DataType.DOUBLE)
+        .addMetric(MET_FLOAT, FieldSpec.DataType.FLOAT)
+        .build();
+  }
+
+  @Override
+  public File createAvroFile()
+      throws IOException {
+
+    // create avro schema
+    org.apache.avro.Schema avroSchema = 
org.apache.avro.Schema.createRecord("myRecord", null, null, false);
+    avroSchema.setFields(ImmutableList.of(
+        new org.apache.avro.Schema.Field(MET_DOUBLE, 
org.apache.avro.Schema.create(org.apache.avro.Schema.Type.DOUBLE),
+            null, null),
+        new org.apache.avro.Schema.Field(MET_FLOAT, 
org.apache.avro.Schema.create(org.apache.avro.Schema.Type.FLOAT),
+            null, null)));
+
+    // create avro file
+    File avroFile = new File(_tempDir, "data.avro");
+    try (DataFileWriter<GenericData.Record> fileWriter = new 
DataFileWriter<>(new GenericDatumWriter<>(avroSchema))) {
+      fileWriter.create(avroSchema, avroFile);
+      double doubleValue = 0.0;
+      float floatValue = 0.0f;
+      for (int i = 0; i < getCountStarResult(); i++) {

Review Comment:
   (minor)
   ```suggestion
         for (int i = 0; i < NUM_DOCS; i++) {
   ```



##########
pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/filter/NumericalFilterOptimizer.java:
##########
@@ -334,14 +334,12 @@ private static Expression 
rewriteRangeExpression(Expression range, FilterKind ki
               // Literal value is less than the bounds of LONG.
               return getExpressionFromBoolean(
                   kind == FilterKind.GREATER_THAN || kind == 
FilterKind.GREATER_THAN_OR_EQUAL);
-            } else {
-              int comparison = Double.compare(actual, converted);
-              // Rewrite range operator
-              rewriteRangeOperator(range, kind, comparison);
-
-              // Rewrite range literal
-              rhs.getLiteral().setDoubleValue(converted);
             }
+            // Do not rewrite range operator since double has higher precision 
than float
+            // If we do, we may introduce problems.
+            // For example, in the previous logic, "> 0.5" will be converted 
into ">= 0.05000000074505806". When the
+            // query reaches a server, the server will convert it to ">= 0.5" 
in

Review Comment:
   I guess this is the real problem. Why does server convert it back to double? 
Is it because on the server side it already lost the information of the 
original type of the literal?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to