Search in sources :

Example 66 with PhoenixArray

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

the class PDataTypeForArraysTest method testVarCharArrayWithNullValues7.

@Test
public void testVarCharArrayWithNullValues7() {
    String[] strArr = new String[6];
    strArr[0] = null;
    strArr[1] = "abc";
    strArr[2] = null;
    strArr[3] = "bcd";
    strArr[4] = null;
    strArr[5] = "cde";
    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 67 with PhoenixArray

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

the class PDataTypeForArraysTest method testArrayConversion.

@Test
public void testArrayConversion() {
    final String[] data = new String[] { "asdf", "qwerty" };
    PhoenixArray phxArray = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, data);
    assertTrue("Converting a PhoenixArray to a PhoenixArray should return the same object", phxArray == PVarcharArray.INSTANCE.toPhoenixArray(phxArray, PVarchar.INSTANCE));
    // Create a skeleton of an Array which isn't a PhoenixArray. Make sure we can convert that.
    Array customArray = new Array() {

        @Override
        public String getBaseTypeName() throws SQLException {
            return "VARCHAR";
        }

        @Override
        public int getBaseType() throws SQLException {
            return Types.VARCHAR;
        }

        @Override
        public Object getArray() throws SQLException {
            return data;
        }

        @Override
        public Object getArray(Map<String, Class<?>> map) throws SQLException {
            return null;
        }

        @Override
        public Object getArray(long index, int count) throws SQLException {
            return null;
        }

        @Override
        public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
            return null;
        }

        @Override
        public ResultSet getResultSet() throws SQLException {
            return null;
        }

        @Override
        public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
            return null;
        }

        @Override
        public ResultSet getResultSet(long index, int count) throws SQLException {
            return null;
        }

        @Override
        public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
            return null;
        }

        @Override
        public void free() throws SQLException {
        }
    };
    PhoenixArray copy = PVarcharArray.INSTANCE.toPhoenixArray(customArray, PVarchar.INSTANCE);
    assertEquals(phxArray, copy);
}
Also used : PCharArray(org.apache.phoenix.schema.types.PCharArray) PUnsignedLongArray(org.apache.phoenix.schema.types.PUnsignedLongArray) PUnsignedSmallintArray(org.apache.phoenix.schema.types.PUnsignedSmallintArray) Array(java.sql.Array) PUnsignedTimestampArray(org.apache.phoenix.schema.types.PUnsignedTimestampArray) PUnsignedDateArray(org.apache.phoenix.schema.types.PUnsignedDateArray) PSmallintArray(org.apache.phoenix.schema.types.PSmallintArray) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PDecimalArray(org.apache.phoenix.schema.types.PDecimalArray) PFloatArray(org.apache.phoenix.schema.types.PFloatArray) PDateArray(org.apache.phoenix.schema.types.PDateArray) PIntegerArray(org.apache.phoenix.schema.types.PIntegerArray) PTinyintArray(org.apache.phoenix.schema.types.PTinyintArray) PUnsignedTinyintArray(org.apache.phoenix.schema.types.PUnsignedTinyintArray) PTimestampArray(org.apache.phoenix.schema.types.PTimestampArray) PBooleanArray(org.apache.phoenix.schema.types.PBooleanArray) PUnsignedIntArray(org.apache.phoenix.schema.types.PUnsignedIntArray) PDoubleArray(org.apache.phoenix.schema.types.PDoubleArray) PUnsignedTimeArray(org.apache.phoenix.schema.types.PUnsignedTimeArray) PTimeArray(org.apache.phoenix.schema.types.PTimeArray) PUnsignedFloatArray(org.apache.phoenix.schema.types.PUnsignedFloatArray) PLongArray(org.apache.phoenix.schema.types.PLongArray) PVarcharArray(org.apache.phoenix.schema.types.PVarcharArray) PUnsignedDoubleArray(org.apache.phoenix.schema.types.PUnsignedDoubleArray) PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) Map(java.util.Map) Test(org.junit.Test)

Example 68 with PhoenixArray

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

the class PDataTypeForArraysTest method testGetArrayLengthForVariableLengthArray.

@Test
public void testGetArrayLengthForVariableLengthArray() {
    String[] strArr = new String[5];
    strArr[0] = "abx";
    strArr[1] = "ereref";
    strArr[2] = "random";
    strArr[3] = "random12";
    strArr[4] = "ranzzz";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes = PVarcharArray.INSTANCE.toBytes(arr);
    ImmutableBytesWritable ptr = new ImmutableBytesWritable(bytes);
    int result = PArrayDataType.getArrayLength(ptr, PVarchar.INSTANCE, null);
    assertEquals(5, result);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) 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 69 with PhoenixArray

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

the class PDataTypeForArraysTest method testForDoubleArray.

@Test
public void testForDoubleArray() {
    Double[] doubleArr = new Double[2];
    doubleArr[0] = 1.06;
    doubleArr[1] = 2.89;
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PDouble.INSTANCE, doubleArr);
    PDoubleArray.INSTANCE.toObject(arr, PDoubleArray.INSTANCE);
    byte[] bytes = PDoubleArray.INSTANCE.toBytes(arr);
    PhoenixArray resultArr = (PhoenixArray) PDoubleArray.INSTANCE.toObject(bytes, 0, bytes.length);
    assertEquals(arr, resultArr);
}
Also used : PhoenixArray(org.apache.phoenix.schema.types.PhoenixArray) PUnsignedDouble(org.apache.phoenix.schema.types.PUnsignedDouble) PDouble(org.apache.phoenix.schema.types.PDouble) Test(org.junit.Test)

Example 70 with PhoenixArray

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

the class PDataTypeForArraysTest method testVarCharArrayComparisonWithGreaterThan255NullsinMiddle1.

@Test
public void testVarCharArrayComparisonWithGreaterThan255NullsinMiddle1() {
    String[] strArr = new String[500];
    strArr[0] = "abc";
    strArr[1] = "bcd";
    strArr[2] = null;
    strArr[3] = null;
    strArr[4] = "bcd";
    strArr[strArr.length - 1] = "abc";
    PhoenixArray arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes1 = PVarcharArray.INSTANCE.toBytes(arr);
    strArr = new String[500];
    strArr[0] = "abc";
    strArr[1] = "bcd";
    strArr[2] = null;
    strArr[3] = null;
    strArr[4] = "bcd";
    strArr[strArr.length - 1] = "abc";
    arr = PArrayDataType.instantiatePhoenixArray(PVarchar.INSTANCE, strArr);
    byte[] bytes2 = PVarcharArray.INSTANCE.toBytes(arr);
    assertTrue(Bytes.compareTo(bytes1, bytes2) == 0);
}
Also used : 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