dssysolyatin commented on code in PR #4001:
URL: https://github.com/apache/calcite/pull/4001#discussion_r1801791290


##########
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:
   input.next() can throw a SQLException, which is a checked exception, so it 
needs to be handled. I also modified the code slightly to use a test utility 
class, like this:
   ```
   catch (SQLException e) {
               throw TestUtil.rethrow(e);
             }
   ```



-- 
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]

Reply via email to