-
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-4787] Replace ImmutableBeans with Immutables #2531
Conversation
This seems like a good idea (rather than relying on our own code). I assume we should also deprecate |
Do we consider this an external api? I figured we would just delete... |
I mentioned that because |
It isn't marked as internal/experimental so I guess deprecated is the right approach. Sadness. I was so hopeful this would be a net negative patch. I love those! |
@@ -360,7 +353,7 @@ public SqlPrettyWriter() { | |||
|
|||
/** Creates a {@link SqlWriterConfig} with Calcite's SQL dialect. */ | |||
public static SqlWriterConfig config() { | |||
return CONFIG; | |||
return SqlWriterConfig.of().withDialect(CalciteSqlDialect.DEFAULT); |
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 guess this is a slight change of behavior as this is not a constant but a new instance each time?
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.
fixed.
@@ -433,4 +424,6 @@ SqlWriterConfig withWhereListItemsOnSeparateLines( | |||
/** Wrap always. Items are on separate lines. */ | |||
TALL | |||
} | |||
|
|||
static SqlWriterConfig DEFAULT = ImmutableSqlWriterConfig.DEFAULT; |
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.
Do we need this? Couldn't we simply reference ImmutableSqlWriterConfig.DEFAULT directly in SqlPrettyWriter.config? Or alternatively deprecate the config function SqlPrettyWriter?
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.
Modified. This isn't included anymore
As @jacques-n said, this is a minimal change - in fact it's just a proof-of-concept. The real change is going to affect hundreds of files, and dozens of lines in each, because there are 142 sub-classes of RelRule.Config. And these configs are public APIs. Removing the Removing the Does Is there anything in |
An interesting side effect is that build fails at Travis: https://app.travis-ci.com/github/apache/calcite/jobs/538524980#L633 It might be related to a relatively "old" Java 1.8 (Travis uses 1.8u252 vs GitHub 1.8u302)
|
Just a small correction @julianhyde
That's incorrect interpretation of the proposed changes. The |
Ah, so is https://www.diffchecker.com/zqTmEKdz not minimal? Could you use withers rather than a builder when initializing DEFAULT? |
Good point. Yes, it could be less impactful. The key difference is that you must use a builder if a property is marked as non-nullable and has no default (since you can't use a 'withFoo' operation until you have a fully valid pojo). When I did the change I was thinking that one or more of those properties were required and not yet default defined. I'll do an update to clarify. |
(I removed this comment. Let's have the conversation in JIRA.) |
Updated simpler example: https://www.diffchecker.com/Ba5a0agP This is possible because the current definition of RelRule.Config declares a default for the OperandTransformer. It's a little icky because the default throws an exception and I'd prefer to delegate the error on missing value to the generated code just like any other missing value. |
Yes. ImmutableBean will have
One can use ImmutableBean.builder()
.from(other) // merges attribute value into builder
.value("foo")
.build(); |
Converting to draft until I have a newer patch ready to review. |
...rc/main/java/org/apache/calcite/rel/rules/materialize/MaterializedViewOnlyAggregateRule.java
Show resolved
Hide resolved
e498f3a
to
6fbe1c2
Compare
You can use |
e319c38
to
11262c9
Compare
@vlsi, I can't figure out what is the right way to express the annotationProcessor dependency constraint in the bom. Any chance you could tell me how to do that? |
@jacques-n , please try the following in Lines 302 to 306 in e533f4b
plugins.withId("java-library") {
dependencies {
+ "annotationProcessor"(platform(project(":bom")))
"implementation"(platform(project(":bom")))
}
} I am not sure if |
Thanks @vlsi, that resolved it. Just needed annotationProcessor, Scratch that, testAnnotationProcessor is also required. |
core/src/main/java/org/apache/calcite/sql/parser/SqlParser.java
Outdated
Show resolved
Hide resolved
baffb4f
to
4a27ff6
Compare
47861a4
to
47448dd
Compare
bd7fb01
to
2fd74ec
Compare
Hey @vlsi, I've pulled out use of immutables in test for this first patch. It's already pretty large. I also cleaned up the gradle stuff. LMK if you think it looks good to merge. Can do a test patch as follow-up. |
2fd74ec
to
eac8e0b
Compare
@vlsi , updated to change condition of task. It seems to work the same in both cases (original and new condition) but I'm happy changing it. |
@@ -14,7 +14,7 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
# | |||
org.gradle.jvmargs=-Xmx512m -XX:MaxMetaspaceSize=512m | |||
org.gradle.jvmargs=-XX:+UseG1GC -Xmx512m -XX:MaxMetaspaceSize=512m |
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.
Why G1GC
?
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.
If you profile the gradle daemon build using old and g1, g1 performs better. It more effectively clears things away. The patch builds with either though.
In general, the gradle settings seem low given the amount of continuous memory builds take. In many cases I see non trivial amounts of time against gc while profiling.
core/build.gradle.kts
Outdated
@@ -16,6 +16,9 @@ | |||
*/ | |||
import com.github.vlsi.gradle.crlf.CrLfSpec | |||
import com.github.vlsi.gradle.crlf.LineEndings | |||
import com.github.vlsi.gradle.ide.dsl.settings | |||
import com.github.vlsi.gradle.ide.dsl.taskTriggers | |||
import org.jetbrains.kotlin.backend.common.onlyIf |
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 onlyIf
looks weird
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.
Not clear if you're asking for a change. It works and was the way I found others doing this. Keep in mind that this is my first effort in gradle and kotlin.
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.
Please drop onlyIf
import. The package name org.jetbrains.kotlin.backend.common
looks as if it has something to do with kotlin backend
which is not something you want to use here. I belive the import has been added by mistake. You should call Task#onlyIf
method which should not require an import.
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 were right. IDE (not)helpfulness. Fixed.
core/build.gradle.kts
Outdated
// only if we aren't running compileJava, since doing twice fails. | ||
onlyIf { project.gradle.taskGraph.hasTask("compileJava") } |
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.
by the way, compileJava
is available from sourceSet.getCompileTaskName("java")
, so onlyIf
could be moved to configureAnnotationSet
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.
Nice, updated.
82d1983
to
c1e5c33
Compare
core/build.gradle.kts
Outdated
options.compilerArgs.add("-proc:only") | ||
org.gradle.api.plugins.internal.JvmPluginsHelper.configureAnnotationProcessorPath(sourceSet, sourceSet.java, options, project) | ||
// only if we aren't running compileJava, since doing twice fails. | ||
onlyIf { project.gradle.taskGraph.hasTask(sourceSet.getCompileTaskName("java")) } |
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 belive hasTask
condition should be reversed.
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.
Nice catch.
The jvm bug is apparently only triggered in the test kotlin/java combination (which is why the build still worked here).
Fixed now.
- Move core rules to use Immutables instead of ImmutableBeans - Update ImmutableBeans to ignore default property return values used by Immutables - Adjust EnumerableProjectToCalcRule so it doesn't try to use proxy behavior with non-empty config - Update MaterializedViewProjectAggregateRule.DEFAULT so it sets fastBailout config property - Update SqlValidator, SqlWriter, SqlParser, SqlToRelConverter, RelDecorrelator, Hoist and RelBuilder to use Immutables for configuration - Switch gradle to use G1 Garbage collector to improve GC performance - Update ConverterRule to have default properties since properties were declared required but had no default values. - Update gradle build to automatically generate annotation source on Intellij and Eclipse sync operations - Add travis_wait to jdk11 checkerframework build to avoid premature termination due to core compile time. - Make ExchangeRemoveConstantKeysRule and ValuesReduceRule consistent with SubqueryRemoveRule by making MatchHandler type parameter concrete. Co-authored-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Replace the use of reflection/dynamic proxies with the AnnotationProcessor provided by Immutables
NOTE: This is an initial patch that only changes one ImmutableBean to Immutables to show what the changes look like