ChinmaySKulkarni commented on a change in pull request #671: PHOENIX-4845
Support using Row Value Constructors in OFFSET clause fo…
URL: https://github.com/apache/phoenix/pull/671#discussion_r363566105
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorOffsetIT.java
##########
@@ -0,0 +1,860 @@
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// RVC Based Offset - Tests
+public class RowValueConstructorOffsetIT extends ParallelStatsDisabledIT {
+
+ static final String SIMPLE_DDL = "CREATE TABLE %s (t_id VARCHAR NOT
NULL,\n" + "k1 INTEGER NOT NULL,\n"
+ + "k2 INTEGER NOT NULL,\n" + "v1 INTEGER,\n" + "v2 VARCHAR,\n"
+ + "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2)) ";
+
+ static final String DATA_DDL = "CREATE TABLE %s (k1 TINYINT NOT NULL,\n" +
"k2 TINYINT NOT NULL,\n"
+ + "k3 TINYINT NOT NULL,\n" + "v1 INTEGER,\n" + "CONSTRAINT pk
PRIMARY KEY (k1, k2, k3)) ";
+
+ String tableName = "T_" + generateUniqueName();
+
+ String dataTableName = "T_" + generateUniqueName();
+
+ String indexName = "INDEX_" + tableName;
+
+ String dataIndexName = "INDEX_" + dataTableName;
+
+ boolean initialized = false;
+ Connection conn;
+
+ @Before
+ public void init() throws SQLException {
+ if (!initialized) {
+ conn = DriverManager.getConnection(getUrl(),
PropertiesUtil.deepCopy(TEST_PROPERTIES));
+
+ String dataTableDDL = String.format(DATA_DDL,dataTableName);
+
+ conn.createStatement().execute(dataTableDDL);
+
+
conn.createStatement().execute(String.format(SIMPLE_DDL,tableName));
+
+ conn.commit();
+
+ String upsertDML = String.format("UPSERT INTO %s VALUES(?,?,?,?)",
dataTableName);
+
+ int nRows = 0;
+ PreparedStatement ps = conn.prepareStatement(upsertDML);
+ for (int k1 = 0; k1 < 4; k1++) {
+ ps.setInt(1, k1);
+ for (int k2 = 0; k2 < 4; k2++) {
+ ps.setInt(2, k2);
+ for (int k3 = 0; k3 < 4; k3++) {
+ ps.setInt(3, k3);
+ ps.setInt(4, nRows);
+ int result = ps.executeUpdate();
+ assertEquals(1, result);
+ nRows++;
+ }
+ }
+ }
+ conn.commit();
+
+ String createIndex = "CREATE INDEX IF NOT EXISTS " + indexName + "
ON " + tableName + " (k2 DESC,k1)";
+ conn.createStatement().execute(createIndex);
+
+
+ String createDataIndex = "CREATE INDEX IF NOT EXISTS " +
dataIndexName + " ON " + dataTableName + " (k2 DESC,k1)";
+ conn.createStatement().execute(createDataIndex);
+ initialized = true;
+
+ conn.commit();
+ }
+ }
+
+ // Test RVC Offset columns must be coercible to a base table
+ @Test
+ public void testRVCOffsetNotCoercible() throws SQLException {
+ String failureSql = String.format("SELECT t_id, k1, k2 FROM %s OFFSET
(t_id, k1, k2)=('a', 'ab', 2)", tableName);
Review comment:
So this should fail because k1 is actually an INTEGER, right? Can we add a
comment? Better yet, since none of these tests have an idea about the details
of the DDL/column names/types etc, it seems odd that they depend on this info.
Can we abstract this away from the test cases? If we were to change the `init`
method then we would have to go about changing each test case with the current
approach.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services