mihaibudiu commented on code in PR #3891:
URL: https://github.com/apache/calcite/pull/3891#discussion_r1695683546


##########
core/src/main/java/org/apache/calcite/sql/dialect/RedshiftSqlDialect.java:
##########
@@ -20,14 +20,13 @@
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeSystem;
 import org.apache.calcite.rel.type.RelDataTypeSystemImpl;
-import org.apache.calcite.sql.SqlDataTypeSpec;
-import org.apache.calcite.sql.SqlDialect;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.SqlUserDefinedTypeNameSpec;
-import org.apache.calcite.sql.SqlWriter;
+import org.apache.calcite.sql.*;

Review Comment:
   Calcite does not like * imports.



##########
core/src/main/java/org/apache/calcite/sql/dialect/RedshiftSqlDialect.java:
##########
@@ -118,4 +117,27 @@ public RedshiftSqlDialect(Context context) {
   @Override public boolean supportsAliasedValues() {
     return false;
   }
+  @Override public void unparseCall(SqlWriter writer, SqlCall call, int 
leftPrec, int rightPrec) {
+    if (call.getOperator() == SqlStdOperatorTable.JSON_OBJECT) {
+      assert call.operandCount() % 2 == 1;
+
+      SqlWriter.Frame frame = writer.startFunCall("");
+      SqlWriter.Frame listFrame = writer.startList("'{' || ", " || '}'");
+      for(int i = 1; i < call.operandCount(); i += 2) {
+        String keyName = call.operand(i).toSqlString(this).toString();
+        String value = call.operand(i + 1).toSqlString(this).toString();
+        keyName = keyName.substring(1, keyName.length() - 1);
+        String jsonFragment = String.format("'\"%s\": ' || COALESCE(CASE WHEN 
%s::varchar ~'^-?\\\\d*(\\\\.\\\\d+)?$' THEN %s::varchar ELSE quote_ident(%s) 
END, 'null')", keyName, value, value, value);

Review Comment:
   this deserves an explanation as a comment



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