Skip to content

Commit

Permalink
Make method-splitting in library code based on a CalciteSystemProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
jduo committed Sep 20, 2024
1 parent fd2de3d commit 8f04243
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ public static Bindable toBindable(Map<String, Object> parameters,
parameters);

final ClassDeclaration expr = relImplementor.implementRoot(rel, prefer);
String s = Expressions.toString(expr.memberDeclarations, "\n", false, true);
String s =
Expressions.toString(expr.memberDeclarations,
"\n", false,
CalciteSystemProperty.ENABLE_METHOD_SPLITTING.value());

if (CalciteSystemProperty.DEBUG.value()) {
Util.debugCode(System.out, s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,12 @@ public final class CalciteSystemProperty<T> {
public static final CalciteSystemProperty<Integer> FUNCTION_LEVEL_CACHE_MAX_SIZE =
intProperty("calcite.function.cache.maxSize", 0, v -> v >= 0);

public static final CalciteSystemProperty<Boolean> ENABLE_CODE_SPLITTING =
booleanProperty("calcite.linq.enable_code_splitting", false);
/** Whether to enable automatic method splitting when generating Java code.
*
* <p>Some queries can generate methods exceeding the JVM limit of 4000 characters per method.
* Enable this feature to automatically detect and split methods larger than the limit. */
public static final CalciteSystemProperty<Boolean> ENABLE_METHOD_SPLITTING =
booleanProperty("calcite.linq.enable_method_splitting", false);

private static CalciteSystemProperty<Boolean> booleanProperty(String key,
boolean defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ static Scalar.Producer baz(ParameterExpression context_,
final ClassDeclaration classDeclaration =
Expressions.classDecl(Modifier.PUBLIC, "Buzz", null,
ImmutableList.of(Scalar.Producer.class), declarations);
String s = Expressions.toString(declarations, "\n", false, true);
String s =
Expressions.toString(declarations, "\n", false,
CalciteSystemProperty.ENABLE_METHOD_SPLITTING.value());
if (CalciteSystemProperty.DEBUG.value()) {
Util.debugCode(System.out, s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ private static String compile(RexBuilder rexBuilder, List<RexNode> constExps,
Expressions.methodDecl(Modifier.PUBLIC, Object[].class,
BuiltInMethod.FUNCTION1_APPLY.method.getName(),
ImmutableList.of(root0_), blockBuilder.toBlock());
String code = Expressions.toString(methodDecl, true);
String code =
Expressions.toString(methodDecl, CalciteSystemProperty.ENABLE_METHOD_SPLITTING.value());
if (CalciteSystemProperty.DEBUG.value()) {
Util.debugCode(System.out, code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ static List<String> innodbFieldNames(final RelDataType rowType) {
InnodbMethod.INNODB_QUERYABLE_QUERY.method, fields,
selectFields, cond, ascOrder));
if (CalciteSystemProperty.DEBUG.value()) {
System.out.println("Innodb: " + Expressions.toString(enumerable, true));
System.out.println(
"Innodb: " + Expressions.toString(enumerable,
CalciteSystemProperty.ENABLE_METHOD_SPLITTING.value()));
}
list.add(Expressions.return_(null, enumerable));
return implementor.result(physType, list.toBlock());
Expand Down

0 comments on commit 8f04243

Please sign in to comment.