Search in sources :

Example 46 with PhoenixArray

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

the class PDataTypeForArraysTest method testPositionAtArrayElementWithDescArray.

@Test
public void testPositionAtArrayElementWithDescArray() {
    Object[] objects = new Object[] { "a", "b", null };
    PhoenixArray arr = new PhoenixArray(PVarchar.INSTANCE, objects);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr, PVarchar.INSTANCE, SortOrder.DESC);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
    PArrayDataTypeDecoder.positionAtArrayElement(ptr, 2, PVarchar.INSTANCE, null);
    String value = (String) PVarchar.INSTANCE.toObject(ptr, SortOrder.DESC);
    assertEquals(null, value);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 47 with PhoenixArray

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

the class PDataTypeForArraysTest method testForVarCharArray.

@Test
public void testForVarCharArray() {
    String[] strArr = new String[2];
    strArr[0] = "abc";
    strArr[1] = "klmnop";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Test(org.junit.Test)

Example 48 with PhoenixArray

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

the class PDataTypeForArraysTest method testForDecimalArray.

@Test
public void testForDecimalArray() {
    BigDecimal[] bigDecimalArr = new BigDecimal[2];
    bigDecimalArr[0] = new BigDecimal(89997);
    bigDecimalArr[1] = new BigDecimal(8999.995f);
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDecimal.INSTANCE, bigDecimalArr);
    PDecimalArray.INSTANCE.toObject(arr, PDecimalArray.INSTANCE);
    byte[] bytes = PDecimalArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PDecimalArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 49 with PhoenixArray

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

the class PDataTypeForArraysTest method testForVarcharArrayWith1ElementInLargerBuffer.

@Test
public void testForVarcharArrayWith1ElementInLargerBuffer() {
    String[] strArr = new String[1];
    strArr[0] = "abx";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    byte[] moreBytes = new byte[bytes.length + 20];
    // Generate some garbage
    for (int i = 0; i < moreBytes.length; i++) {
        moreBytes[i] = (byte) -i;
    }
    System.arraycopy(bytes, 0, moreBytes, 10, bytes.length);
    PhoenixArray resultArr = (PhoenixArray) PVarcharArray.INSTANCE.toObject(moreBytes, 10, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PUnsignedSmallint(org.apache.phoenix.schema.types.PUnsignedSmallint) PUnsignedTinyint(org.apache.phoenix.schema.types.PUnsignedTinyint) PTinyint(org.apache.phoenix.schema.types.PTinyint) PSmallint(org.apache.phoenix.schema.types.PSmallint) Test(org.junit.Test)

Example 50 with PhoenixArray

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

the class StringToArrayFunctionIT method testStringToArrayFunction6.

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

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