-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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-5984] Allow disabling field trim via SqlToRelConverter
config
#3436
Conversation
|
||
Hook.TRIMMED.run(root.rel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this is same code,why you changed this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no change in the code itself, I've only moved this logic inside a condition based on the config that determined whether or not to trim unused fields
+ " join \"hr\".\"emps\" as \"e\" on \"d\".\"deptno\" = \"e\".\"deptno\" \n") | ||
.withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER, | ||
(Consumer<Holder<Config>>) configHolder -> | ||
configHolder.set(configHolder.get().withTrimUnusedFields(true))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the sql is same as above,the withTrimUnusedFields method has different parameters, but the plan is the same.
Why did you use this SQL example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing field trimming happens by
- Specifying SQL2RelConverter Config
or - Specifying a Program that contains the Field trimming program (the standard program)
I tried to showcase all the different ways config 1 & 2 will enable trimming, while trimming will be disabled if both 1. Converter config and 2. Program Config disable it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @WegdanGhazi ,thanks for your reply.
I have saw the difference between testJoinWithTrimmingEnabledByProgramAndConfig
and testJoinWithTrimmingEnabledByProgram
is the withTrimUnusedFields param value,one is false,another is true.
But the input sql and expected plan is same,so I'm a little confused about the purpose of these two unit tests.I thought a few code comments illustrating this case would make it easier for others to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! Will add comments, thanks!
@@ -8247,6 +8343,33 @@ private static String sums(int n, boolean c) { | |||
return b.toString(); | |||
} | |||
|
|||
/** A program that omits {@link TrimFieldsProgram}. */ | |||
private static Program getProgram() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe could use org.apache.calcite.tools.Programs#standard(org.apache.calcite.rel.metadata.RelMetadataProvider) method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The standard program is initialized as follows:
return sequence(subQuery(metadataProvider),
new DecorrelateProgram(),
new TrimFieldsProgram(),
program1,
// Second planner pass to do physical "tweaks". This the first time
// that EnumerableCalcRel is introduced.
calc(metadataProvider));
Which includes the TrimFieldsProgram()
, so I had to manually initialize one to avoid adding that program.
What do you think? Do you suggest a better way to create the program without TrimFieldsProgram()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make the standard(RelMetadataProvider) method has parameters with RelMetadataProvider and boolean
flag?
The boolean
flag indicates whether TrimFieldsProgram should be added,The standard() method default value is true.I finded Programs#standard(RelMetadataProvider) method only used in Programs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good! Will go for that!
@WegdanGhazi thank you for opening this PR, left a couple of comments! |
Kudos, SonarCloud Quality Gate passed! |
Hi @WegdanGhazi ,If you think we could add this feature in 1.36.0,please change this jira Fix Version to 1.36.0. And also need the others review. |
Hi @LakeShen, Thank you so much for the review! The current state is that we're waiting for more reviews, right? |
Yes,you are right. |
* <a href="https://issues.apache.org/jira/browse/CALCITE-5984">[CALCITE-5984]</a> | ||
* Disabling trimming of unused fields via config and program. | ||
* Case: trimmingByProgram: false ; trimmingByConfig: true. */ | ||
@Test void testJoinWithTrimmingEnabledByConfig() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use @ParameterizedTest from junit5 or make your custom input collection and unite 3 below tests into one, wdyt ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
} | ||
|
||
/** Returns the standard program with user metadata provider. */ | ||
public static Program standard(RelMetadataProvider metadataProvider) { | ||
public static Program standard(RelMetadataProvider metadataProvider, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that this is a public API that we need to consider compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about using method overloads to keep the functionality? Pushed something.
@@ -679,6 +679,7 @@ static void assertPrepare( | |||
Connection connection, | |||
String sql, | |||
boolean materializationsEnabled, | |||
List<Pair<Hook, Consumer>> hooks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also a public API (testkit are expected to be used by third party projects)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an overload function to maintain the public API.
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
CALCITE-5984 Allow disabling field trim via
SqlToRelConverter
configUse the value of
isTrimUnusedFields
set toSqlToRelConverter.Config
to determine whether to trim unused fields, making it possible to completely disable trimming.As seen here, the Prepare#trim function creates a new instance of
SqlToRelConverter.Config
, overwriting existingisTrimUnusedFields
settings.This PR fixes this by checking the boolean
trimUnusedFields
before calling#trim
.Unit tests were added to ensure that trimming can be completely disabled by controlling:
isTrimUnusedFields
onSqlToRelConverter.Config
.TrimFieldsProgram
from the initialization of the optimization program.