Search in sources :

Example 6 with Primitive

use of org.apache.calcite.linq4j.tree.Primitive in project calcite by apache.

the class PrimitiveTest method testSendSource.

/**
 * Test for
 * {@link Primitive#send(org.apache.calcite.linq4j.tree.Primitive.Source, org.apache.calcite.linq4j.tree.Primitive.Sink)}.
 */
@Test
public void testSendSource() {
    final List<Object> list = new ArrayList<Object>();
    for (Primitive primitive : Primitive.values()) {
        primitive.send(new Primitive.Source() {

            public boolean getBoolean() {
                list.add(boolean.class);
                return true;
            }

            public byte getByte() {
                list.add(byte.class);
                return 0;
            }

            public char getChar() {
                list.add(char.class);
                return 0;
            }

            public short getShort() {
                list.add(short.class);
                return 0;
            }

            public int getInt() {
                list.add(int.class);
                return 0;
            }

            public long getLong() {
                list.add(long.class);
                return 0;
            }

            public float getFloat() {
                list.add(float.class);
                return 0;
            }

            public double getDouble() {
                list.add(double.class);
                return 0;
            }

            public Object getObject() {
                list.add(Object.class);
                return 0;
            }
        }, new Primitive.Sink() {

            public void set(boolean v) {
                list.add(boolean.class);
                list.add(v);
            }

            public void set(byte v) {
                list.add(byte.class);
                list.add(v);
            }

            public void set(char v) {
                list.add(char.class);
                list.add(v);
            }

            public void set(short v) {
                list.add(short.class);
                list.add(v);
            }

            public void set(int v) {
                list.add(int.class);
                list.add(v);
            }

            public void set(long v) {
                list.add(long.class);
                list.add(v);
            }

            public void set(float v) {
                list.add(float.class);
                list.add(v);
            }

            public void set(double v) {
                list.add(double.class);
                list.add(v);
            }

            public void set(Object v) {
                list.add(Object.class);
                list.add(v);
            }
        });
    }
    assertThat(list.toString(), equalTo("[boolean, boolean, true, " + "byte, byte, 0, " + "char, char, \u0000, " + "short, short, 0, " + "int, int, 0, " + "long, long, 0, " + "float, float, 0.0, " + "double, double, 0.0, " + "class java.lang.Object, class java.lang.Object, 0, " + "class java.lang.Object, class java.lang.Object, 0]"));
}
Also used : ArrayList(java.util.ArrayList) Primitive(org.apache.calcite.linq4j.tree.Primitive) Test(org.junit.Test)

Aggregations

Primitive (org.apache.calcite.linq4j.tree.Primitive)6 ArrayList (java.util.ArrayList)3 Expression (org.apache.calcite.linq4j.tree.Expression)3 BigDecimal (java.math.BigDecimal)2 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)2 UnaryExpression (org.apache.calcite.linq4j.tree.UnaryExpression)2 RelDataType (org.apache.calcite.rel.type.RelDataType)2 Type (java.lang.reflect.Type)1 PhysType (org.apache.calcite.adapter.enumerable.PhysType)1 JdbcConvention (org.apache.calcite.adapter.jdbc.JdbcConvention)1 JdbcRel (org.apache.calcite.adapter.jdbc.JdbcRel)1 JdbcSchema (org.apache.calcite.adapter.jdbc.JdbcSchema)1 ByteString (org.apache.calcite.avatica.util.ByteString)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 ExpressionType (org.apache.calcite.linq4j.tree.ExpressionType)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1 Test (org.junit.Test)1