use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class StringToArrayFunctionIT method testStringToArrayFunctionWithUpsert2.
@Test
public void testStringToArrayFunctionWithUpsert2() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String tableName = generateUniqueName();
String ddl = "CREATE TABLE " + tableName + " (region_name VARCHAR PRIMARY KEY,varchars VARCHAR[])";
conn.createStatement().execute(ddl);
String dml = "UPSERT INTO " + tableName + "(region_name,varchars) VALUES('SF Bay Area', STRING_TO_ARRAY('a, b, -, c', ', ', '-'))";
conn.createStatement().execute(dml);
conn.commit();
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT varchars FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
assertTrue(rs.next());
PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "a", "b", null, "c" });
assertEquals(expected, rs.getArray(1));
assertFalse(rs.next());
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class StringToArrayFunctionIT method testStringToArrayFunction9.
@Test
public void testStringToArrayFunction9() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT STRING_TO_ARRAY(region_name, ' ', '4') FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
assertTrue(rs.next());
PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "SF", "Bay", "Area" });
assertEquals(expected, rs.getArray(1));
assertFalse(rs.next());
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class StringToArrayFunctionIT method testStringToArrayFunctionWithUpsert1.
@Test
public void testStringToArrayFunctionWithUpsert1() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String tableName = generateUniqueName();
String ddl = "CREATE TABLE " + tableName + " (region_name VARCHAR PRIMARY KEY,varchars VARCHAR[])";
conn.createStatement().execute(ddl);
String dml = "UPSERT INTO " + tableName + "(region_name,varchars) VALUES('SF Bay Area', STRING_TO_ARRAY('hello, world, :-)', ', '))";
conn.createStatement().execute(dml);
conn.commit();
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT varchars FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
assertTrue(rs.next());
PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "hello", "world", ":-)" });
assertEquals(expected, rs.getArray(1));
assertFalse(rs.next());
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class StringToArrayFunctionIT method testStringToArrayFunctionWithUpsertSelect1.
@Test
public void testStringToArrayFunctionWithUpsertSelect1() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String table1 = generateUniqueName();
String ddl = "CREATE TABLE " + table1 + " (region_name VARCHAR PRIMARY KEY, varchar VARCHAR)";
conn.createStatement().execute(ddl);
String table2 = generateUniqueName();
ddl = "CREATE TABLE " + table2 + " (region_name VARCHAR PRIMARY KEY, varchars VARCHAR[])";
conn.createStatement().execute(ddl);
String dml = "UPSERT INTO " + table1 + "(region_name, varchar) VALUES('SF Bay Area', 'a,b,c,d')";
conn.createStatement().execute(dml);
dml = "UPSERT INTO " + table1 + "(region_name, varchar) VALUES('SF Bay Area2', '1,2,3,4')";
conn.createStatement().execute(dml);
conn.commit();
dml = "UPSERT INTO " + table2 + "(region_name, varchars) SELECT region_name, STRING_TO_ARRAY(varchar, ',') FROM " + table1;
conn.createStatement().execute(dml);
conn.commit();
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT varchars FROM " + table2);
assertTrue(rs.next());
PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "a", "b", "c", "d" });
assertEquals(expected, rs.getArray(1));
assertTrue(rs.next());
expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "1", "2", "3", "4" });
assertEquals(expected, rs.getArray(1));
assertFalse(rs.next());
}
use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.
the class StringToArrayFunctionIT method testStringToArrayFunction1.
@Test
public void testStringToArrayFunction1() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT STRING_TO_ARRAY(string1, delimiter1) FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
assertTrue(rs.next());
PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "a", "b", "c", "d" });
assertEquals(expected, rs.getArray(1));
assertFalse(rs.next());
}
Aggregations