This is an automated email from the ASF dual-hosted git repository.
xxyu pushed a commit to branch kylin3
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/kylin3 by this push:
new ba760d5 [KYLIN-4382] Unable to use DATE type in prepared statements
ba760d5 is described below
commit ba760d52ac02e272e7768cab58c6c91f0008a030
Author: juntao zhang <[email protected]>
AuthorDate: Tue Feb 8 20:40:57 2022 +0800
[KYLIN-4382] Unable to use DATE type in prepared statements
---
.../java/org/apache/kylin/jdbc/DriverTest.java | 23 ++++++++++++++++++++++
.../apache/kylin/query/relnode/OLAPContext.java | 14 +++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/jdbc/src/test/java/org/apache/kylin/jdbc/DriverTest.java
b/jdbc/src/test/java/org/apache/kylin/jdbc/DriverTest.java
index 908ce21..30c0442 100644
--- a/jdbc/src/test/java/org/apache/kylin/jdbc/DriverTest.java
+++ b/jdbc/src/test/java/org/apache/kylin/jdbc/DriverTest.java
@@ -22,11 +22,15 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.sql.Connection;
+import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
import java.util.Properties;
import org.apache.calcite.avatica.DriverVersion;
@@ -273,6 +277,25 @@ public class DriverTest {
conn2.close();
}
+ // fix KYLIN-4382 Unable to use DATE type in prepared statements
+ @Ignore("require dev sandbox")
+ @Test
+ public void testKYLIN4382() throws SQLException, ParseException {
+ Driver driver = new Driver();
+ Properties info = new Properties();
+ info.put("user", "ADMIN");
+ info.put("password", "KYLIN");
+ Connection conn =
driver.connect("jdbc:kylin://localhost:7070/default", info);
+ PreparedStatement state = conn.prepareStatement("select count(*) from
test_kylin_fact where cal_dt=?");
+ state.setDate(1, new Date(new SimpleDateFormat("yyyy-MM-dd",
Locale.ROOT).parse("2012-01-01").getTime()));
+ ResultSet resultSet = state.executeQuery();
+ assertTrue(resultSet.next());
+ assertTrue(resultSet.getLong(1) > 0);
+ resultSet.close();
+ state.close();
+ conn.close();
+ }
+
private void printResultSet(ResultSet rs) throws SQLException {
ResultSetMetaData meta = rs.getMetaData();
System.out.println("Data:");
diff --git
a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
index 2f3ad4c..08e4dc9 100755
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPContext.java
@@ -59,10 +59,13 @@ import org.apache.kylin.storage.hybrid.HybridInstance;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*/
public class OLAPContext {
+ private final static Logger logger =
LoggerFactory.getLogger(OLAPContext.class);
public static final String PRM_ACCEPT_PARTIAL_RESULT =
"AcceptPartialResult";
public static final String PRM_USER_AUTHEN_INFO = "UserAuthenInfo";
@@ -335,8 +338,15 @@ public class OLAPContext {
return value;
}
- if (column.getType().isDateTimeFamily()){
- value = String.valueOf(DateFormat.stringToMillis(value));
+ if (column.getType().isDateTimeFamily()) {
+ String oldValue = value;
+ if (column.getType().isDate()) {
+ // It seems the dynamic parameter has been changed to the date
integer value
+ value = String.valueOf(Long.parseLong(value) * 86400000L);
+ } else {
+ value = String.valueOf(DateFormat.stringToMillis(value));
+ }
+ logger.debug("Column value changed from {} to {}", oldValue,
value);
}
return value;
}