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

refactor(queries): change parser to use JSQLParser #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ subprojects {
// Forced dependencies
api("org.slf4j:slf4j-api:2.0.16")
}

//SQL parser
implementation 'com.github.jsqlparser:jsqlparser:5.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.kestra.core.serializers.FileSerde;
import lombok.*;
import lombok.experimental.SuperBuilder;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.statement.Statements;
import org.slf4j.Logger;

import java.io.BufferedWriter;
Expand Down Expand Up @@ -54,10 +56,10 @@ public AbstractJdbcQueries.MultiQueryOutput run(RunContext runContext) throws Ex
savepoint = initializeSavepoint(conn);

String sqlRendered = runContext.render(this.sql, this.additionalVars);
String[] queries = sqlRendered.split(";[^']");

for(String query : queries) {
Statements statements = CCJSqlParserUtil.parseStatements(sqlRendered);
for(net.sf.jsqlparser.statement.Statement statement : statements) {
//Create statement, execute
String query = statement.toString();
stmt = createPreparedStatementAndPopulateParameters(runContext, conn, query);
stmt.setFetchSize(this.getFetchSize());
logger.debug("Starting query: {}", query);
Expand Down
Loading