Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed JSON_OBJECT issue #3891

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kenstott
Copy link

Redshift has no JSON_OBJECT function, this rewrites JSON_OBJECT using ANSI SQL.

@caicancai
Copy link
Member

You need to create a jira case

@kenstott
Copy link
Author

kenstott commented Jul 29, 2024 via email

@kenstott
Copy link
Author

CALCITE-6505 has been created.

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to write at least one test to exercise this code.
you also need to use the same title for the commit message and PR as you used in the JIRA case.

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this deserves an explanation as a comment

import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.SqlUserDefinedTypeNameSpec;
import org.apache.calcite.sql.SqlWriter;
import org.apache.calcite.sql.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calcite does not like * imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants