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

[CALCITE-5241] Implement CHAR function #2878

Closed
wants to merge 6 commits into from

Conversation

JiajunBernoulli
Copy link
Contributor

@JiajunBernoulli JiajunBernoulli commented Aug 21, 2022

Notes: char(n) is different from chr(n) when n large than 256. chr(n) be added in https://issues.apache.org/jira/browse/CALCITE-2510

@@ -462,6 +462,16 @@ public static ByteString right(ByteString s, int n) {
return s.substring(len - n);
}

/**
* SQL CHAR(int) function.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

explain the difference between this and chr. It isn't int vs long.

Copy link
Contributor

Choose a reason for hiding this comment

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

also make the javadoc consistent with other javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should be bigint.

OperandTypes.INTEGER,
SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {ORACLE, POSTGRESQL})
Copy link
Contributor

Choose a reason for hiding this comment

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

CHR and CHAR need javadoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added javadoc.

*/
public static final SqlReturnTypeInference CHAR_FORCE_NULLABLE =
CHAR.andThen(SqlTypeTransforms.FORCE_NULLABLE);

Copy link
Contributor

Choose a reason for hiding this comment

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

not 'nullable Char', but 'nullable CHAR(1)'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to it.

@@ -1492,9 +1492,6 @@ protected static Calendar getCalendarNotTooNear(int timeUnit) {
f.checkScalar("{fn ASCII('ABC')}", "65", "INTEGER NOT NULL");
f.checkNull("{fn ASCII(cast(null as varchar(1)))}");

if (false) {
f.checkScalar("{fn CHAR(code)}", null, "");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this test? The goal of the change is to implement JDBC '{fn CHAR}'

Copy link
Contributor Author

@JiajunBernoulli JiajunBernoulli Aug 25, 2022

Choose a reason for hiding this comment

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

Sorry, my mistake.

@@ -339,6 +339,7 @@ public enum BuiltInMethod {
UPPER(SqlFunctions.class, "upper", String.class),
LOWER(SqlFunctions.class, "lower", String.class),
ASCII(SqlFunctions.class, "ascii", String.class),
CHAR(SqlFunctions.class, "charN", int.class),
REPEAT(SqlFunctions.class, "repeat", String.class, int.class),
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be CHAR(SqlFunctions.class, "charN", long.class)?

and don't you also need CHR(SqlFunctions.class, "chr", long.class)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your careful review, I changed to them.

julianhyde added a commit to julianhyde/calcite that referenced this pull request Sep 8, 2022
Rename methods in SqlFunctions to make semantics clearer.

CHAR is semi-strict (sometimes returns null if argument is not null).

Improve descriptions of CHAR, CHR, {fn CHAR}.

Close apache#2878
julianhyde pushed a commit to julianhyde/calcite that referenced this pull request Sep 8, 2022
@asfgit asfgit closed this in 89c940c Sep 9, 2022
kennethmhc pushed a commit to kennethmhc/calcite that referenced this pull request Sep 15, 2022
tanclary pushed a commit to tanclary/calcite that referenced this pull request Nov 11, 2022
tanclary pushed a commit to tanclary/calcite that referenced this pull request Nov 28, 2022
gleonSun pushed a commit to gleonSun/calcite that referenced this pull request Apr 10, 2023
gleonSun added a commit to gleonSun/calcite that referenced this pull request Jun 12, 2023
For SDK dialect conversion

Calcite 1.30 changed Rexcall operator from SqlCaseOperator to SqlPostfixOperator in RelOptUtil#isDistinctFromInternal

Calcite 1.30 remove EquiJoinInfo and NonEquiJoinInfo, but we need rexbuilder

Calcite 1.30 implement CHAR function

Fallback the logic of the simplification condition to version 1.16, otherwise it may lead to a failure to prune partitions

Revert "Fallback the logic of the simplification condition to version 1.16, otherwise it may lead to a failure to prune partitions"

This reverts commit 27f1a28.

[Follow up] Fallback the logic of the simplification condition to version 1.16, otherwise it may lead to a failure to prune partitions

Refer to KE-36291 for an adapted method to simplify the filter condition

Refer to AL-5295 fix the ut about CharNColumnTest#testCharNColumn

Calcite 1.30 fix about SumCaseWhenFunctionRule and CountDistinctCaseWhenFunctionRule

[Follow up] Fix ProjectRel replacement and old agg replacement caused by RelBuilder#aggregate method

Roll back Calcite's computeDigest and simplifyCase logic from previous versions to ensure correct matching of Kylin models

[Follow up] Fix the way digest is calculated, delete the previous logic

Fix exception in Calcite 1.30 where data type conversion affected logical plan changes

Fix with Sort optimize and Trim function

Revert "Calcite 1.30 implement CHAR function"

This reverts commit 0e1f6b0.

[CALCITE-5241] Implement CHAR function for MySQL and Spark, also JDBC '{fn CHAR(n)}'

Close apache#2878

Debug for Calcite deploy

Calcite 1.30 don't keep the precision of BigDecimal, add scale to fix exception

Fix SqlBasicCall's Deep Copy Logic Raises Rule Optimization Exception and TDVT test

Change kap-external-guava20 to kylin-external-guava30 and package name

Remove the default Unicode operation on the quoteStringLiteral function in Calcite 1.30
gleonSun added a commit to gleonSun/calcite that referenced this pull request Jun 12, 2023
For SDK dialect conversion

Calcite 1.30 changed Rexcall operator from SqlCaseOperator to SqlPostfixOperator in RelOptUtil#isDistinctFromInternal

Calcite 1.30 remove EquiJoinInfo and NonEquiJoinInfo, but we need rexbuilder

Calcite 1.30 implement CHAR function

Fallback the logic of the simplification condition to version 1.16, otherwise it may lead to a failure to prune partitions

Revert "Fallback the logic of the simplification condition to version 1.16, otherwise it may lead to a failure to prune partitions"

This reverts commit 27f1a28.

[Follow up] Fallback the logic of the simplification condition to version 1.16, otherwise it may lead to a failure to prune partitions

Refer to KE-36291 for an adapted method to simplify the filter condition

Refer to AL-5295 fix the ut about CharNColumnTest#testCharNColumn

Calcite 1.30 fix about SumCaseWhenFunctionRule and CountDistinctCaseWhenFunctionRule

[Follow up] Fix ProjectRel replacement and old agg replacement caused by RelBuilder#aggregate method

Roll back Calcite's computeDigest and simplifyCase logic from previous versions to ensure correct matching of Kylin models

[Follow up] Fix the way digest is calculated, delete the previous logic

Fix exception in Calcite 1.30 where data type conversion affected logical plan changes

Fix with Sort optimize and Trim function

Revert "Calcite 1.30 implement CHAR function"

This reverts commit 0e1f6b0.

[CALCITE-5241] Implement CHAR function for MySQL and Spark, also JDBC '{fn CHAR(n)}'

Close apache#2878

Debug for Calcite deploy

Calcite 1.30 don't keep the precision of BigDecimal, add scale to fix exception

Fix SqlBasicCall's Deep Copy Logic Raises Rule Optimization Exception and TDVT test

Change kap-external-guava20 to kylin-external-guava30 and package name

Remove the default Unicode operation on the quoteStringLiteral function in Calcite 1.30
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.

2 participants