Search in sources :

Example 1 with ExpressionType

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);
        }
    }
}
Also used : Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method) ExpressionType(org.apache.phoenix.expression.ExpressionType) Test(org.junit.Test)

Example 2 with ExpressionType

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) {
        }
    }
}
Also used : Constructor(java.lang.reflect.Constructor) ExpressionType(org.apache.phoenix.expression.ExpressionType) Test(org.junit.Test)

Example 3 with ExpressionType

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);
    }
}
Also used : FunctionExpression(org.apache.phoenix.expression.function.FunctionExpression) ExpressionType(org.apache.phoenix.expression.ExpressionType) TypeMismatchException(org.apache.phoenix.schema.TypeMismatchException) SQLException(java.sql.SQLException)

Example 4 with ExpressionType

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);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Expression(org.apache.phoenix.expression.Expression) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) DataInputStream(java.io.DataInputStream) ExpressionType(org.apache.phoenix.expression.ExpressionType)

Aggregations

ExpressionType (org.apache.phoenix.expression.ExpressionType)4 Constructor (java.lang.reflect.Constructor)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 Expression (org.apache.phoenix.expression.Expression)1 FunctionExpression (org.apache.phoenix.expression.function.FunctionExpression)1 TypeMismatchException (org.apache.phoenix.schema.TypeMismatchException)1