Search in sources :

Example 6 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class ArrayPrependFunctionIT method testArrayPrependFunctionNulls2.

@Test
public void testArrayPrependFunctionNulls2() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    String[] s = new String[] { "1", "2" };
    String tableName = generateUniqueName();
    initTableWithVarArray(conn, tableName, "VARCHAR", s, null);
    String[] s2 = new String[] { null, "1", "2" };
    PhoenixArray array2 = (PhoenixArray) conn.createArrayOf("VARCHAR", s2);
    conn = DriverManager.getConnection(getUrl());
    ResultSet rs;
    rs = conn.createStatement().executeQuery("SELECT ARRAY_PREPEND(b,a) FROM " + tableName + " WHERE k = 'a'");
    assertTrue(rs.next());
    assertEquals(array2, rs.getArray(1));
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 7 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class StringToArrayFunctionIT method testStringToArrayFunction5.

@Test
public void testStringToArrayFunction5() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    ResultSet rs;
    rs = conn.createStatement().executeQuery("SELECT STRING_TO_ARRAY(string2, delimiter2) FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
    assertTrue(rs.next());
    PhoenixArray 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 8 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class StringToArrayFunctionIT method testStringToArrayFunction3.

@Test
public void testStringToArrayFunction3() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    ResultSet rs;
    rs = conn.createStatement().executeQuery("SELECT STRING_TO_ARRAY(string1, delimiter1, 'a') FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
    assertTrue(rs.next());
    PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { null, "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)

Example 9 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class StringToArrayFunctionIT method testStringToArrayFunction4.

@Test
public void testStringToArrayFunction4() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    ResultSet rs;
    rs = conn.createStatement().executeQuery("SELECT STRING_TO_ARRAY(string1, delimiter1, 'd') FROM " + tableName + " WHERE region_name = 'SF Bay Area'");
    assertTrue(rs.next());
    PhoenixArray expected = new PhoenixArray(PVarchar.INSTANCE, new Object[] { "a", "b", "c", null });
    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 10 with PhoenixArray

use of org.apache.phoenix.schema.types.PhoenixArray in project phoenix by apache.

the class RegexpSplitFunctionTest method evalExp.

private String[] evalExp(Expression exp) throws SQLException {
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    boolean eval = exp.evaluate(null, ptr);
    assertTrue(eval);
    PhoenixArray evalRes = (PhoenixArray) exp.getDataType().toObject(ptr);
    String[] res = (String[]) evalRes.getArray();
    return res;
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray)

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