@Test public void testNoSCNInConnectionProps() throws Exception { Properties props = new Properties(); DriverManager.getConnection(getUrl(), props); }
@Test public void testServerArrayElementProjection1() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t(a INTEGER PRIMARY KEY, arr INTEGER ARRAY)"); ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT arr[1] from t"); assertTrue(QueryUtil.getExplainPlan(rs).contains(" SERVER ARRAY ELEMENT PROJECTION")); } finally { conn.createStatement().execute("DROP TABLE IF EXISTS t"); conn.close(); } }
@Test public void testServerArrayElementProjection3() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t(a INTEGER PRIMARY KEY, arr INTEGER ARRAY, arr2 VARCHAR ARRAY)"); ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT arr, arr[1], arr2[1] from t"); assertTrue(QueryUtil.getExplainPlan(rs).contains(" SERVER ARRAY ELEMENT PROJECTION")); } finally { conn.createStatement().execute("DROP TABLE IF EXISTS t"); conn.close(); } }
@Test public void testServerArrayElementProjection5() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 INTEGER ARRAY)"); ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT arr1, arr1[1], ARRAY_ELEM(ARRAY_APPEND(arr1, arr2[1]), 1), p, arr2[2] from t"); assertTrue(QueryUtil.getExplainPlan(rs).contains(" SERVER ARRAY ELEMENT PROJECTION")); } finally { conn.createStatement().execute("DROP TABLE IF EXISTS t"); conn.close(); } }
@Test public void testServerArrayElementProjection2() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t(a INTEGER PRIMARY KEY, arr INTEGER ARRAY)"); ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT arr, arr[1] from t"); assertFalse(QueryUtil.getExplainPlan(rs).contains(" SERVER ARRAY ELEMENT PROJECTION")); } finally { conn.createStatement().execute("DROP TABLE IF EXISTS t"); conn.close(); } }
@Test public void testServerArrayElementProjection4() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 INTEGER ARRAY)"); ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT arr1, arr1[1], ARRAY_APPEND(ARRAY_APPEND(arr1, arr2[2]), arr2[1]), p from t"); assertTrue(QueryUtil.getExplainPlan(rs).contains(" SERVER ARRAY ELEMENT PROJECTION")); } finally { conn.createStatement().execute("DROP TABLE IF EXISTS t"); conn.close(); } }
@Test public void testInvalidNegativeArrayIndex() throws Exception { String query = "SELECT a_double_array[-20] FROM table_with_array"; Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute(query); fail(); } catch (Exception e) { } } @Test
@Test public void testNonArrayColumnWithIndex() throws Exception { String query = "SELECT a_float[1] FROM table_with_array"; Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute(query); fail(); } catch (Exception e) { } }
@Test public void testServerArrayElementProjectionWithArrayPrimaryKey() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t(arr INTEGER ARRAY PRIMARY KEY)"); ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT arr[1] from t"); assertFalse(QueryUtil.getExplainPlan(rs).contains(" SERVER ARRAY ELEMENT PROJECTION")); } finally { conn.createStatement().execute("DROP TABLE IF EXISTS t"); conn.close(); } }
@Test public void testCreateNullableInPKMiddle() throws Exception { String query = "CREATE TABLE foo(i integer not null, j integer null, k integer not null CONSTRAINT pk PRIMARY KEY(i,j,k))"; Connection conn = DriverManager.getConnection(getUrl()); try { PreparedStatement statement = conn.prepareStatement(query); statement.execute(); fail(); } catch (SQLException e) { // expected assertTrue(e.getMessage().contains("PK columns may not be both fixed width and nullable")); } }
@Test public void testInvalidArrayElemRefInUpsert() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute("CREATE TABLE t (k VARCHAR PRIMARY KEY, a INTEGER[10], B INTEGER[10])"); try { conn.createStatement().execute("UPSERT INTO t(k,a[2]) VALUES('A', 5)"); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.PARSER_ERROR.getErrorCode(), e.getErrorCode()); } conn.close(); }
@Test public void testForcingRowKeyOrderNotUseRoundRobinIterator() throws Exception { Properties props = new Properties(); props.setProperty(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.toString(true)); Connection conn = DriverManager.getConnection(getUrl(), props); testForceRowKeyOrder(conn, false); testForceRowKeyOrder(conn, true); }
@Test public void testPlanForOrderByOrGroupByNotUseRoundRobin() throws Exception { Properties props = new Properties(); props.setProperty(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.toString(false)); Connection conn = DriverManager.getConnection(getUrl(), props); testOrderByOrGroupByDoesntUseRoundRobin(conn, true); testOrderByOrGroupByDoesntUseRoundRobin(conn, false); }
@Test public void testVarbinaryArrayNotSupported() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute("CREATE TABLE t (k VARCHAR PRIMARY KEY, a VARBINARY[10])"); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.VARBINARY_ARRAY_NOT_SUPPORTED.getErrorCode(), e.getErrorCode()); } conn.close(); }
@Test public void testKeyValueColumnInPKConstraint() throws Exception { String ddl = "CREATE TABLE t (a.k VARCHAR, b.v VARCHAR CONSTRAINT pk PRIMARY KEY(k))"; Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute(ddl); fail(); } catch (SQLException e) { assertTrue(e.getErrorCode() == SQLExceptionCode.PRIMARY_KEY_WITH_FAMILY_NAME.getErrorCode()); } }
@Test public void testUnknownColumnInPKConstraint() throws Exception { String ddl = "CREATE TABLE t (k1 VARCHAR, b.v VARCHAR CONSTRAINT pk PRIMARY KEY(k1, k2))"; Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute(ddl); fail(); } catch (ColumnNotFoundException e) { assertEquals("K2",e.getColumnName()); } }
@Test public void testDuplicatePKColumn() throws Exception { String ddl = "CREATE TABLE t (k1 VARCHAR, k1 VARCHAR CONSTRAINT pk PRIMARY KEY(k1))"; Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute(ddl); fail(); } catch (ColumnAlreadyExistsException e) { assertEquals("K1",e.getColumnName()); } }
@Test public void testDuplicateKVColumn() throws Exception { String ddl = "CREATE TABLE t (k1 VARCHAR, v1 VARCHAR, v2 VARCHAR, v1 INTEGER CONSTRAINT pk PRIMARY KEY(k1))"; Connection conn = DriverManager.getConnection(getUrl()); try { conn.createStatement().execute(ddl); fail(); } catch (ColumnAlreadyExistsException e) { assertEquals("V1",e.getColumnName()); } }
@Test public void testMultiCFProjection() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); String ddl = "CREATE TABLE multiCF (k integer primary key, a.a varchar, b.b varchar)"; conn.createStatement().execute(ddl); String query = "SELECT COUNT(*) FROM multiCF"; QueryPlan plan = getQueryPlan(query,Collections.emptyList()); plan.iterator(); Scan scan = plan.getContext().getScan(); assertTrue(scan.getFilter() instanceof FirstKeyOnlyFilter); assertEquals(1, scan.getFamilyMap().size()); }
@Test public void testNullDefaultRemoved() throws Exception { String ddl = "CREATE TABLE table_with_default (" + "pk INTEGER PRIMARY KEY, " + "v VARCHAR DEFAULT null)"; Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute(ddl); PTable table = conn.unwrap(PhoenixConnection.class).getMetaDataCache() .getTableRef(new PTableKey(null,"TABLE_WITH_DEFAULT")).getTable(); assertNull(table.getColumnForColumnName("V").getExpressionStr()); }