Skip to content

Commit

Permalink
Use DateReader in DefaultResultSetProcessor (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsrnhld authored Jul 18, 2024
1 parent 6797c0b commit 0d850cb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.bakdata.conquery.sql.conversion.SqlConverter;
import com.bakdata.conquery.sql.conversion.dialect.SqlDialect;
import com.bakdata.conquery.sql.conversion.dialect.SqlDialectFactory;
import com.bakdata.conquery.sql.execution.ResultSetProcessor;
import com.bakdata.conquery.sql.execution.ResultSetProcessorFactory;
import com.bakdata.conquery.sql.execution.SqlExecutionResult;
import com.bakdata.conquery.sql.execution.SqlExecutionService;
Expand Down Expand Up @@ -48,7 +49,8 @@ public LocalNamespace createNamespace(NamespaceStorage namespaceStorage, MetaSto
DSLContext dslContext = dslContextWrapper.getDslContext();
SqlDialect sqlDialect = dialectFactory.createSqlDialect(databaseConfig.getDialect());

SqlExecutionService sqlExecutionService = new SqlExecutionService(dslContext, ResultSetProcessorFactory.create(sqlDialect));
ResultSetProcessor resultSetProcessor = ResultSetProcessorFactory.create(config, sqlDialect);
SqlExecutionService sqlExecutionService = new SqlExecutionService(dslContext, resultSetProcessor);
NodeConversions nodeConversions = new NodeConversions(idColumns, sqlDialect, dslContext, databaseConfig, sqlExecutionService);
SqlConverter sqlConverter = new SqlConverter(nodeConversions);
ExecutionManager<SqlExecutionResult> executionManager = new SqlExecutionManager(sqlConverter, sqlExecutionService, metaStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.util.DateReader;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
class DefaultResultSetProcessor implements ResultSetProcessor {

private final ConqueryConfig config;
private final SqlCDateSetParser sqlCDateSetParser;

@Override
Expand Down Expand Up @@ -48,11 +50,12 @@ public Boolean getBoolean(ResultSet resultSet, int columnIndex) throws SQLExcept

@Override
public Number getDate(ResultSet resultSet, int columnIndex) throws SQLException {
Date date = resultSet.getDate(columnIndex);
if (date == null) {
String dateString = resultSet.getString(columnIndex);
if (dateString == null) {
return null;
}
return date.toLocalDate().toEpochDay();
DateReader dateReader = config.getLocale().getDateReader();
return dateReader.parseToLocalDate(dateString).toEpochDay();
}

@Override
Expand Down Expand Up @@ -97,7 +100,11 @@ public List<BigDecimal> getMoneyList(ResultSet resultSet, int columnIndex) throw

@Override
public List<Number> getDateList(ResultSet resultSet, int columnIndex) throws SQLException {
return fromString(resultSet, columnIndex, (string) -> Date.valueOf(string).toLocalDate().toEpochDay());
return fromString(resultSet, columnIndex, this::parseWithDateReader);
}

private Number parseWithDateReader(String string) {
return config.getLocale().getDateReader().parseToLocalDate(string).toEpochDay();
}

private <T> List<T> fromString(ResultSet resultSet, int columnIndex, Function<String, T> parseFunction) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.bakdata.conquery.sql.execution;

import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.sql.conversion.dialect.SqlDialect;

public class ResultSetProcessorFactory {

public static ResultSetProcessor create(SqlDialect sqlDialect) {
return new DefaultResultSetProcessor(sqlDialect.getCDateSetParser());
public static ResultSetProcessor create(ConqueryConfig config, SqlDialect sqlDialect) {
return new DefaultResultSetProcessor(config, sqlDialect.getCDateSetParser());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.bakdata.conquery.sql.conversion.dialect.PostgreSqlDialect;
import com.bakdata.conquery.sql.conversion.model.SqlQuery;
import com.bakdata.conquery.sql.conversion.supplier.DateNowSupplier;
import com.bakdata.conquery.sql.execution.ResultSetProcessor;
import com.bakdata.conquery.sql.execution.ResultSetProcessorFactory;
import com.bakdata.conquery.sql.execution.SqlExecutionService;
import lombok.Getter;
Expand Down Expand Up @@ -84,7 +85,8 @@ static void after() throws IOException {
public void shouldThrowException() {
// This can be removed as soon as we switch to a full integration test including the REST API
I18n.init();
SqlExecutionService executionService = new SqlExecutionService(dslContextWrapper.getDslContext(), ResultSetProcessorFactory.create(testSqlDialect));
ResultSetProcessor resultSetProcessor = ResultSetProcessorFactory.create(config, testSqlDialect);
SqlExecutionService executionService = new SqlExecutionService(dslContextWrapper.getDslContext(), resultSetProcessor);
SqlQuery validQuery = new TestSqlQuery("SELECT 1");
Assertions.assertThatNoException().isThrownBy(() -> executionService.execute(validQuery));

Expand Down

0 comments on commit 0d850cb

Please sign in to comment.