Search in sources :

Example 51 with PhoenixArray

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());
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 52 with PhoenixArray

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());
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 53 with PhoenixArray

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());
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 54 with PhoenixArray

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());
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 55 with PhoenixArray

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());
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Aggregations

PhoenixArray (org.apache.phoenix.schema.types.PhoenixArray)107 Test (org.junit.Test)97 Connection (java.sql.Connection)25 ResultSet (java.sql.ResultSet)25 PSmallint (org.apache.phoenix.schema.types.PSmallint)25 PTinyint (org.apache.phoenix.schema.types.PTinyint)25 PUnsignedSmallint (org.apache.phoenix.schema.types.PUnsignedSmallint)25 PUnsignedTinyint (org.apache.phoenix.schema.types.PUnsignedTinyint)25 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)23 PreparedStatement (java.sql.PreparedStatement)7 Properties (java.util.Properties)7 BaseTest (org.apache.phoenix.query.BaseTest)7 Array (java.sql.Array)6 PDouble (org.apache.phoenix.schema.types.PDouble)5 PLong (org.apache.phoenix.schema.types.PLong)4 PUnsignedLong (org.apache.phoenix.schema.types.PUnsignedLong)4 Timestamp (java.sql.Timestamp)3 PTimestamp (org.apache.phoenix.schema.types.PTimestamp)3 PUnsignedDouble (org.apache.phoenix.schema.types.PUnsignedDouble)3 PUnsignedTimestamp (org.apache.phoenix.schema.types.PUnsignedTimestamp)3