mihaibudiu commented on code in PR #4001:
URL: https://github.com/apache/calcite/pull/4001#discussion_r1797240379
##########
mongodb/src/test/java/org/apache/calcite/adapter/mongodb/MongoAdapterTest.java:
##########
@@ -778,6 +738,50 @@ private void checkPredicate(int expected, String q) {
});
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-6623">[CALCITE-6623]
+ * MongoDB adapter throws a java.lang.ClassCastException when Decimal128 or
Binary types are
+ * used, or when a primitive value is cast to a string</a>. */
+ @Test void testRuntimeTypes() {
+ assertModel(MODEL)
+ .query("select cast(_MAP['loc'] AS varchar) "
+ + "from \"mongo_raw\".\"zips\" where _MAP['_id']='99801'")
+ .returnsCount(1)
+ .returnsValue("[-134.529429, 58.362767]");
+
+ assertModel(MODEL)
+ .query("select cast(_MAP['warehouse_postal_code'] AS bigint) AS
postal_code_as_bigint"
+ + " from \"mongo_raw\".\"warehouse\" where _MAP['warehouse_id']=1")
+ .returnsCount(1)
+ .returnsValue("55555")
+ .typeIs("[POSTAL_CODE_AS_BIGINT BIGINT]");
+
+ assertModel(MODEL)
+ .query("select cast(_MAP['warehouse_postal_code'] AS varchar) AS
postal_code_as_varchar"
+ + " from \"mongo_raw\".\"warehouse\" where _MAP['warehouse_id']=1")
+ .returnsCount(1)
+ .returnsValue("55555")
+ .typeIs("[POSTAL_CODE_AS_VARCHAR VARCHAR]");
+
+ assertModel(MODEL)
+ .query("select cast(_MAP['binaryData'] AS binary) from
\"mongo_raw\".\"datatypes\"")
+ .returnsCount(1)
+ .returns(resultSet -> {
+ try {
+ resultSet.next();
+ //CHECKSTYLE: IGNORE 1
+ assertThat(new String(resultSet.getBytes(1),
StandardCharsets.UTF_8), is("binaryData"));
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
Review Comment:
I suspect that this is unreachable, maybe this should be documented
##########
mongodb/src/main/java/org/apache/calcite/adapter/mongodb/MongoEnumerator.java:
##########
@@ -119,8 +127,34 @@ static Function1<Document, Object> getter(
: (Function1) listGetter(fields);
}
+ /**
+ * Converts the given object to a specific runtime type based on the
provided class.
+ *
+ * @param fieldName The name of the field being processed, used for error
reporting if
+ * conversion fails.
+ * @param o The object to be converted. If `null`, the method returns `null`
immediately.
+ * @param clazz The target class to which the object `o` should be converted.
+ * @return The converted object as an instance of the specified `clazz`, or
`null` if `o` is
+ * `null`.
+ *
+ * @throws IllegalArgumentException if the object `o` cannot be converted to
the desired
+ * `clazz` type, including a message indicating the field name, expected
data type, and the
+ * invalid value.
+ *
+ * <h3>Conversion Details</h3>:
+ *
+ * <p>If the target type is one of the following, the method performs
specific conversions:
+ * <ul>
+ * <li>`Long`: Converts a `Date` or `BsonTimestamp` object into the
respective epoch time
+ * (milliseconds).
+ * <li>`BigDecimal`: Converts a `Decimal128` object into a `BigDecimal`
instance.
+ * <li>`String`: Converts arrays to string and uses `String.valueOf(o)`
for other objects.
+ * <li>`ByteString`: Converts a `Binary` object into a `ByteString`
instance.
Review Comment:
Is Double supposed to be supported?
After recent changes Calcite supports Double RexLiteral values.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]