palashc commented on code in PR #2232:
URL: https://github.com/apache/phoenix/pull/2232#discussion_r2214674494


##########
phoenix-core-client/src/main/java/org/apache/phoenix/expression/util/bson/SQLComparisonExpressionUtils.java:
##########
@@ -636,6 +648,69 @@ private static boolean contains(final String fieldKey, 
final String containsValu
     return false;
   }
 
+  /**
+   * Returns true if the type of the value of the field key is same as the 
provided type.
+   * The provided type should be one of the following:
+   * S – String
+   * SS – String set
+   * N – Number
+   * NS – Number set
+   * B – Binary
+   * BS – Binary set
+   * BOOL – Boolean
+   * NULL – Null
+   * L – List
+   * M – Map
+   * @param fieldKey The field key for which value is checked for field_type.
+   * @param type The type to check against the type of the field value.
+   * @param rawBsonDocument Bson Document representing the cell value on which 
the comparison is
+   * to be performed.
+   * @param comparisonValuesDocument Bson Document with values placeholder.
+   * @return True if the value of the field is of the given type, false 
otherwise
+   */
+  private static boolean isFieldOfType(final String fieldKey, final String 
type,
+                                  final RawBsonDocument rawBsonDocument,
+                                  final BsonDocument comparisonValuesDocument) 
{
+    BsonValue topLevelValue = rawBsonDocument.get(fieldKey);
+    BsonValue fieldValue = topLevelValue != null ?
+            topLevelValue :
+            CommonComparisonExpressionUtils.getFieldFromDocument(fieldKey, 
rawBsonDocument);
+    if (fieldValue == null) {
+      return false;
+    }
+    BsonValue typeBsonVal = comparisonValuesDocument.get(type);
+    if (typeBsonVal == null) {
+      throw new IllegalArgumentException("Value for type was not found in the 
comparison values document.");
+    }
+    switch (((BsonString) typeBsonVal).getValue()) {
+      case "S":
+        return fieldValue.isString();
+      case "N":
+        return fieldValue.isNumber();
+      case "B":
+        return fieldValue.isBinary();
+      case "BOOL":
+        return fieldValue.isBoolean();
+      case "NULL":
+        return fieldValue.isNull();
+      case "L":
+        return fieldValue.isArray();
+      case "M":
+        return fieldValue.isDocument();
+      case "SS":
+        return CommonComparisonExpressionUtils.isBsonSet(fieldValue)

Review Comment:
   done



-- 
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: issues-unsubscr...@phoenix.apache.org

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

Reply via email to