use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class PhoenixRuntime method getSqlTypeName.
/**
*
* @param pCol
* @return sql type name that could be used in DDL statements, dynamic column types etc.
*/
public static String getSqlTypeName(PColumn pCol) {
PDataType dataType = pCol.getDataType();
Integer maxLength = pCol.getMaxLength();
Integer scale = pCol.getScale();
return getSqlTypeName(dataType, maxLength, scale);
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class ScanRangesTest method foreach.
private static Collection<?> foreach(KeyRange[][] ranges, int[] widths, KeyRange keyRange, boolean expectedResult) {
List<List<KeyRange>> slots = Lists.transform(Lists.newArrayList(ranges), ARRAY_TO_LIST);
RowKeySchemaBuilder builder = new RowKeySchemaBuilder(10);
for (final int width : widths) {
if (width > 0) {
builder.addField(new PDatum() {
@Override
public boolean isNullable() {
return false;
}
@Override
public PDataType getDataType() {
return PChar.INSTANCE;
}
@Override
public Integer getMaxLength() {
return width;
}
@Override
public Integer getScale() {
return null;
}
@Override
public SortOrder getSortOrder() {
return SortOrder.getDefault();
}
}, false, SortOrder.getDefault());
} else {
builder.addField(new PDatum() {
@Override
public boolean isNullable() {
return false;
}
@Override
public PDataType getDataType() {
return PVarchar.INSTANCE;
}
@Override
public Integer getMaxLength() {
return width;
}
@Override
public Integer getScale() {
return null;
}
@Override
public SortOrder getSortOrder() {
return SortOrder.getDefault();
}
}, false, SortOrder.getDefault());
}
}
ScanRanges scanRanges = ScanRanges.createSingleSpan(builder.build(), slots);
return foreach(scanRanges, widths, keyRange, expectedResult);
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingAllPDataTypesToVarBinary.
@Test
public void testCoerceExpressionSupportsCoercingAllPDataTypesToVarBinary() throws Exception {
for (PDataType p : PDataType.values()) {
if (!p.isArrayType()) {
LiteralExpression v = LiteralExpression.newConstant(map.get(p.getJavaClass()), p);
CoerceExpression e = new CoerceExpression(v, PVarbinary.INSTANCE);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
e.evaluate(null, ptr);
Object obj = e.getDataType().toObject(ptr);
assertTrue("Coercing to VARBINARY failed for PDataType " + p, obj instanceof byte[]);
}
}
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class CoerceExpressionTest method testCoerceExpressionSupportsCoercingAllPDataTypesToBinary.
@Test
public void testCoerceExpressionSupportsCoercingAllPDataTypesToBinary() throws Exception {
for (PDataType p : PDataType.values()) {
if (!p.isArrayType()) {
LiteralExpression v = LiteralExpression.newConstant(map.get(p.getJavaClass()), p);
CoerceExpression e = new CoerceExpression(v, PBinary.INSTANCE);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
e.evaluate(null, ptr);
Object obj = e.getDataType().toObject(ptr);
assertTrue("Coercing to BINARY failed for PDataType " + p, obj instanceof byte[]);
}
}
}
use of org.apache.phoenix.schema.types.PDataType in project phoenix by apache.
the class SortOrderExpressionTest method evaluateAndAssertResult.
private void evaluateAndAssertResult(Expression expression, Object expectedResult, String context) {
context = context == null ? "" : context;
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
assertTrue(expression.evaluate(null, ptr));
PDataType dataType = expression.getDataType();
SortOrder sortOrder = expression.getSortOrder();
Object result = dataType.toObject(ptr.get(), ptr.getOffset(), ptr.getLength(), dataType, sortOrder);
assertEquals(context, expectedResult, result);
}
Aggregations