use of org.apache.phoenix.expression.ExpressionType in project phoenix by apache.
the class BuiltinFunctionConstructorTest method testChildrenListConstructors.
@Test
public void testChildrenListConstructors() throws Exception {
ExpressionType[] types = ExpressionType.values();
for (int i = 0; i < types.length; i++) {
try {
Class<? extends Expression> expressionClass = types[i].getExpressionClass();
if (!Modifier.isAbstract(expressionClass.getModifiers()) && (ScalarFunction.class.isAssignableFrom(expressionClass)) && (expressionClass != UDFExpression.class)) {
Method cloneMethod = expressionClass.getMethod("clone", List.class);
assertNotNull(cloneMethod);
// ScalarFunctions that implement clone(List<Expression>) don't need to implement a constructor that takes a List<Expression>
if (cloneMethod.getDeclaringClass() == ScalarFunction.class) {
Constructor cons = expressionClass.getDeclaredConstructor(List.class);
assertTrue("Constructor for " + expressionClass + " is not public", Modifier.isPublic(cons.getModifiers()));
}
}
} catch (Exception e) {
throw new RuntimeException("Unable to find required List<Expression> constructor " + types[i].getExpressionClass().getName(), e);
}
}
}
use of org.apache.phoenix.expression.ExpressionType in project phoenix by apache.
the class BuiltinFunctionConstructorTest method testNoArgumentConstructors.
@Test
public void testNoArgumentConstructors() {
ExpressionType[] types = ExpressionType.values();
for (int i = 0; i < types.length; i++) {
try {
if (!AggregateFunction.class.isAssignableFrom(types[i].getExpressionClass())) {
Constructor cons = types[i].getExpressionClass().getDeclaredConstructor();
cons.setAccessible(true);
cons.newInstance();
}
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (Exception e) {
}
}
}
use of org.apache.phoenix.expression.ExpressionType in project phoenix by apache.
the class ParseNodeFactory method initBuiltInFunctionMap.
/**
* Reflect this class and populate static structures from it.
* Don't initialize in static block because we have a circular dependency
*/
private static synchronized void initBuiltInFunctionMap() {
if (!BUILT_IN_FUNCTION_MAP.isEmpty()) {
return;
}
Class<? extends FunctionExpression> f = null;
try {
// Reflection based parsing which yields direct explicit function evaluation at runtime
for (int i = 0; i < CLIENT_SIDE_BUILT_IN_FUNCTIONS.size(); i++) {
f = CLIENT_SIDE_BUILT_IN_FUNCTIONS.get(i);
addBuiltInFunction(f);
}
for (ExpressionType et : ExpressionType.values()) {
Class<? extends Expression> ec = et.getExpressionClass();
if (FunctionExpression.class.isAssignableFrom(ec)) {
@SuppressWarnings("unchecked") Class<? extends FunctionExpression> c = (Class<? extends FunctionExpression>) ec;
addBuiltInFunction(f = c);
}
}
} catch (Exception e) {
throw new RuntimeException("Failed initialization of built-in functions at class '" + f + "'", e);
}
}
use of org.apache.phoenix.expression.ExpressionType in project phoenix by apache.
the class UngroupedAggregateRegionObserver method deserializeExpressions.
private static List<Expression> deserializeExpressions(byte[] b) {
ByteArrayInputStream stream = new ByteArrayInputStream(b);
try {
DataInputStream input = new DataInputStream(stream);
int size = WritableUtils.readVInt(input);
List<Expression> selectExpressions = Lists.newArrayListWithExpectedSize(size);
for (int i = 0; i < size; i++) {
ExpressionType type = ExpressionType.values()[WritableUtils.readVInt(input)];
Expression selectExpression = type.newInstance();
selectExpression.readFields(input);
selectExpressions.add(selectExpression);
}
return selectExpressions;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
stream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Aggregations