Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/org/rumbledb/api/SequenceWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import java.util.List;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import lombok.extern.log4j.Log4j2;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.sql.DataFrameWriter;
import org.apache.spark.sql.Dataset;
Expand Down Expand Up @@ -43,6 +42,8 @@
* {@link SerializationParameters#getMethod()}, which is the single source of truth for the output
* format.
*/

@Log4j2
public class SequenceWriter {

private static final int SINGLE_PARTITION_CAP = 1000000000;
Expand Down Expand Up @@ -287,11 +288,10 @@ public void save(String path) {
// DataFrame mode: delegate to Spark's DataFrameWriter, using the serialization method
// as the Spark output format (json/csv/parquet/other).
if (this.dataFrameWriter != null) {
Logger logger = LogManager.getLogger(SequenceWriter.class);
for (Map.Entry<String, String> option : this.serializationParameters.getSparkOptions().entrySet()) {
logger.info("Writing with option " + option.getKey() + " : " + option.getValue());
log.info("Writing with option " + option.getKey() + " : " + option.getValue());
}
logger.info("Writing to format " + method);
log.info("Writing to format " + method);
DataFrameWriter<Row> writerWithOptions = applyStoredSparkOptions(this.dataFrameWriter);
String target = FileSystemUtil.convertURIToStringForSpark(outputUri);
if (method.equalsIgnoreCase("json")) {
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/org/rumbledb/cli/LoggingConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.rumbledb.cli;

import java.util.Arrays;
import java.util.Locale;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.spi.StandardLevel;
import org.rumbledb.config.model.DebugConfig;
import org.rumbledb.exceptions.CliException;
import org.rumbledb.spark.SparkSessionManager;

final class LoggingConfiguration {
private static final String LOGGER_NAME = "org.rumbledb";
private static final Level DEFAULT_APPLICATION_LEVEL = Level.WARN;
private static final Level DEFAULT_SPARK_LEVEL = Level.OFF;
private static final String VALID_LEVELS = String.join(
", ",
Arrays.stream(StandardLevel.values())
.map(StandardLevel::name)
.map(level -> level.toLowerCase(Locale.ROOT))
.toList()
);

private LoggingConfiguration() {
}

static void configure(DebugConfig debugConfig) {
Configurator.setLevel(LOGGER_NAME, resolveApplicationLevel(debugConfig));
SparkSessionManager.setLogLevel(resolveSparkLevel(debugConfig));
}

private static Level resolveApplicationLevel(DebugConfig debugConfig) {
if (isBlank(debugConfig.logLevel())) {
return DEFAULT_APPLICATION_LEVEL;
}
return parseLevel(debugConfig.logLevel(), "--log-level");
}

private static Level resolveSparkLevel(DebugConfig debugConfig) {
if (isBlank(debugConfig.sparkLogLevel())) {
return DEFAULT_SPARK_LEVEL;
}
return parseLevel(debugConfig.sparkLogLevel(), "--spark-log-level");
}

private static Level parseLevel(String rawLevel, String optionName) {
String normalizedLevel = rawLevel.trim().toUpperCase(Locale.ROOT);
try {
StandardLevel.valueOf(normalizedLevel);
} catch (IllegalArgumentException e) {
throw new CliException(
"Invalid "
+ optionName
+ " value: "
+ rawLevel
+ ". Valid values are: "
+ VALID_LEVELS
+ "."
);
}
return Level.toLevel(normalizedLevel);
}

private static boolean isBlank(String value) {
return value == null || value.isBlank();
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/rumbledb/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@
System.exit(0);
} else {
configuration = invocation.configuration();
LoggingConfiguration.configure(configuration.debug());
}
} catch (Exception e) {
System.err.println("⚠️ CLI Error: " + e.getMessage());
ConsoleOutput.error("⚠️ CLI Error: " + e.getMessage());
System.exit(42);
}

try {
if (configuration.mode() == RumbleMode.REPL) {

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / build

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (RegexPatternUtilsTest)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (BackwardsCompatibilityTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (JavaAPITest)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (FrontendTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (StaticTypeTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (NativeFLWORRuntimeTestsParallelismDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (org.rumbledb.config.RumbleConfigurationTest)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (XQueryTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (org.rumbledb.api.RumbleConfigurationTest)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (XMLTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (SparkRuntimeTestsParallelismDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (Bugs)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (NativeFLWORRuntimeTestsNativeDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (IcebergUpdateRuntimeTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (MLTestsNativeDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (MLTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (NativeFLWORRuntimeTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (NativeFLWORRuntimeTestsDataFramesDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (SparkRuntimeTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (SparkRuntimeTestsNativeDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (SparkRuntimeTestsDataFramesDeactivated)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (RuntimeTestsNoParallelism)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (DeltaUpdateRuntimeTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (RuntimeTests)

Potential null pointer access: The variable configuration may be null at this location

Check warning on line 72 in src/main/java/org/rumbledb/cli/Main.java

View workflow job for this annotation

GitHub Actions / tests (RuntimeTestsNoInlining)

Potential null pointer access: The variable configuration may be null at this location
launchShell(invocation);
} else if (configuration.input().query() != null || configuration.input().queryPath() != null) {
runQueryExecutor(invocation);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/rumbledb/cli/arguments/DebugArguments.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@ public final class DebugArguments {
)
private Boolean logging;

@Option(
names = "--log-level",
paramLabel = "level",
description = "Sets the diagnostic logging level. Valid values: off, fatal, error, warn, info, debug, trace, all."
)
private String logLevel;

@Option(
names = "--spark-log-level",
paramLabel = "level",
description = "Sets the Spark logging level. Valid values: off, fatal, error, warn, info, debug, trace, all."
)
private String sparkLogLevel;

public DebugConfig toConfig() {
DebugConfig.DebugConfigBuilder builder = DebugConfig.builder();

OptionConversion.applyBooleanIfPresent(this.printIteratorTree, builder::printIteratorTree);
OptionConversion.applyBooleanIfPresent(this.showErrorInfo, builder::showErrorInfo);
OptionConversion.applyBooleanIfPresent(this.logging, builder::logging);
OptionConversion.applyIfPresent(this.logLevel, builder::logLevel);
OptionConversion.applyIfPresent(this.sparkLogLevel, builder::sparkLogLevel);

return builder.build();
}
Expand Down
37 changes: 17 additions & 20 deletions src/main/java/org/rumbledb/compiler/ExecutionModeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package org.rumbledb.compiler;

import org.apache.log4j.LogManager;
import lombok.extern.log4j.Log4j2;
import org.rumbledb.bindings.DataFrameBinding;
import org.rumbledb.bindings.ExternalBindings;
import org.rumbledb.config.RumbleConfiguration;
Expand Down Expand Up @@ -96,6 +96,8 @@
/**
* Static context visitor implements a multi-pass algorithm that enables function hoisting
*/

@Log4j2
public class ExecutionModeVisitor extends AbstractNodeVisitor<StaticContext> {

private VisitorConfig visitorConfig;
Expand Down Expand Up @@ -162,18 +164,15 @@ public StaticContext visitVariableReference(VariableReferenceExpression expressi
expression.getStaticSequenceType().getArity().equals(Arity.ZeroOrMore)
) {
if (expression.getStaticSequenceType().getItemType().isObjectItemType()) {
System.err.println(
"[WARNING] Forcing execution mode of variable "
+ expression.getVariableName()
+ " to DataFrame based on static object* type."
log.warn(
"Forcing execution mode of variable {} to DataFrame based on static object* type.",
expression.getVariableName()
);
expression.setHighestExecutionMode(DATAFRAMEifConfigurationAllows());
return argument;
}
}
System.err.println(
"[WARNING] Forcing execution mode of variable " + expression.getVariableName() + " to local."
);
log.warn("Forcing execution mode of variable {} to local.", expression.getVariableName());
expression.setHighestExecutionMode(ExecutionMode.LOCAL);
return argument;
}
Expand Down Expand Up @@ -699,12 +698,11 @@ public StaticContext visitValidateTypeExpression(ValidateTypeExpression expressi
targetType.getItemType().isObjectItemType()
&& targetType.getItemType().isCompatibleWithDataFrames(this.configuration)
) {
LogManager.getLogger("ExecutionModeVisitor")
.info(
"Validation against "
+ expression.getSequenceType().getItemType().getName()
+ " compatible with data frames."
);
log.info(
"Validation against "
+ expression.getSequenceType().getItemType().getName()
+ " compatible with data frames."
);
expression.setHighestExecutionMode(DATAFRAMEifConfigurationAllows());
} else {
if (
Expand All @@ -723,12 +721,11 @@ public StaticContext visitValidateTypeExpression(ValidateTypeExpression expressi
targetType.getItemType().isObjectItemType()
&& targetType.getItemType().isCompatibleWithDataFrames(this.configuration)
) {
LogManager.getLogger("ExecutionModeVisitor")
.info(
"Validation against "
+ expression.getSequenceType().getItemType().getName()
+ " compatible with data frames."
);
log.info(
"Validation against "
+ expression.getSequenceType().getItemType().getName()
+ " compatible with data frames."
);
expression.setHighestExecutionMode(DATAFRAMEifConfigurationAllows());
} else {
if (
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/rumbledb/compiler/InferTypeVisitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.rumbledb.compiler;

import lombok.extern.log4j.Log4j2;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -164,6 +166,7 @@
/**
* This visitor infers a static SequenceType for each expression in the query
*/
@Log4j2
public class InferTypeVisitor extends AbstractNodeVisitor<StaticContext> {

private RumbleConfiguration configuration;
Expand Down Expand Up @@ -393,8 +396,8 @@ public StaticContext visitVariableReference(VariableReferenceExpression expressi
variableType = expression.getStaticContext().getVariableSequenceType(expression.getVariableName());
// we also set variableReference type
if (variableType == null) {
System.err.println(
"[WARNING] Variable reference type was null so we infer it. Please let us know as we would like to look into it."
log.warn(
"Variable reference type was null so we infer it. Please let us know as we would like to look into it."
);
variableType = SequenceType.createSequenceType("item*");
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/rumbledb/compiler/TranslationVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package org.rumbledb.compiler;

import lombok.extern.log4j.Log4j2;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
Expand Down Expand Up @@ -210,6 +211,7 @@
*
* @author Stefan Irimescu, Can Berker Cikis, Ghislain Fourny, Andrea Rinaldi
*/
@Log4j2
public class TranslationVisitor extends JsoniqParserBaseVisitor<Node> {

private StaticContext moduleContext;
Expand Down Expand Up @@ -292,7 +294,7 @@ public Node visitMainModule(JsoniqParser.MainModuleContext ctx) {
// We override with a context item declaration if not present already.
Program program = (Program) this.visitProgram(ctx.program());
if (!prolog.hasContextItemDeclaration() && getExternalVariableType(Name.CONTEXT_ITEM) != null) {
System.err.println("[WARNING] Adding context item declaration.");
log.warn("Adding context item declaration.");
prolog.addDeclaration(
new VariableDeclaration(
Name.CONTEXT_ITEM,
Expand Down Expand Up @@ -2606,7 +2608,7 @@ public Node visitArrayConstructor(JsoniqParser.ArrayConstructorContext ctx) {
createMetadataFromContext(sqCtx)
);
} else {
System.err.println("Not concatenating to comma.");
log.debug("Not concatenating to comma.");
// In JSONiq 4.0, the square array constructor behaves like in XQuery 4.0.
for (JsoniqParser.ExprSingleContext memberCtx : memberCtxs) {
memberExpressions.add((Expression) this.visitExprSingle(memberCtx));
Expand Down
42 changes: 29 additions & 13 deletions src/main/java/org/rumbledb/compiler/VisitorHelpers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.rumbledb.compiler;

import lombok.extern.log4j.Log4j2;
import org.antlr.v4.runtime.BailErrorStrategy;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
Expand Down Expand Up @@ -38,14 +39,15 @@
import java.util.ArrayList;
import java.util.List;

@Log4j2
public class VisitorHelpers {

public static RuntimeIterator generateRuntimeIterator(Node node, RumbleConfiguration conf) {
RuntimeIterator result = new RuntimeIteratorVisitor(conf).visit(node, null);
if (conf.debug().printIteratorTree() || conf.debug().logging()) {
StringBuilder sb = new StringBuilder();
result.print(sb, 0);
System.err.println(sb);
log.debug(sb);
}
return result;
}
Expand Down Expand Up @@ -118,21 +120,35 @@ private static MainModule applyTypeDependentOptimizations(MainModule module) {
*/
private static void debugPrintTree(Module node, RumbleConfiguration conf) {
if (conf.debug().printIteratorTree() || conf.debug().logging()) {
System.err.println("***************");
System.err.println("Expression tree");
System.err.println("***************");
System.err.println("Unset execution modes: " + node.numberOfUnsetExecutionModes());
System.err.println(node);
System.err.println();
System.err.println(node.getStaticContext());
log.debug(
"""
***************
Expression tree
***************
Unset execution modes: {}
{}

{}\
""",
node.numberOfUnsetExecutionModes(),
node,
node.getStaticContext()
);
}
}

private static void debugPrintHeader(RumbleConfiguration conf, String header) {
if (conf.debug().printIteratorTree() || conf.debug().logging()) {
System.err.println("*".repeat(header.length()));
System.err.println(header);
System.err.println("*".repeat(header.length()));
log.debug(
"""
{}
{}
{}\
""",
"*".repeat(header.length()),
header,
"*".repeat(header.length())
);
}
}

Expand Down Expand Up @@ -570,7 +586,7 @@ private static void populateExecutionModes(
debugPrintTree(module, conf);
}
if (module.numberOfUnsetExecutionModes() > 0) {
System.err.println(
log.warn(
"[WARNING] Some execution modes could not be set. The query may still work, but we would welcome a bug report."
);
}
Expand Down Expand Up @@ -619,7 +635,7 @@ private static void populateExecutionModes(
debugPrintTree(module, conf);
}
if (module.numberOfUnsetExecutionModes() > 0) {
System.err.println(
log.warn(
"[WARNING] Some execution modes could not be set. The query may still work, but we would welcome a bug report."
);
}
Expand Down
Loading
Loading