tempto icon indicating copy to clipboard operation
tempto copied to clipboard

Add Support for results that are Map Types

Open mattsfuller opened this issue 9 years ago • 1 comments

I am unable to add a test for the map aggregate histogram function because tempto does not support having a query return a map type.

Query:

presto:default> select histogram(n_regionkey) from nation;
           _col0           
---------------------------
 {0=5, 1=5, 2=5, 3=5, 4=5} 
(1 row)

Query 20150909_163252_00146_vfjfr, FINISHED, 2 nodes
Splits: 2 total, 2 done (100.00%)
0:00 [25 rows, 2.17KB] [125 rows/s, 10.9KB/s]

But when run with Tempto:

2015-09-09 23:10:08 DEBUG [MapAggregateTests.testSimpleHistogramInt_1441819507415] c.t.t.i.i.TestInitializationListener - test failure java.lang.RuntimeException: Unsupported sql type JAVA_OBJECT
    at com.teradata.tempto.internal.query.QueryResultValueComparator.compare(QueryResultValueComparator.java:100)
    at com.teradata.tempto.assertions.QueryAssert.rowsEqual(QueryAssert.java:334)
    at com.teradata.tempto.assertions.QueryAssert.containsExactly(QueryAssert.java:227)
    at com.teradata.tempto.assertions.QueryAssert.containsExactly(QueryAssert.java:247)
    at com.facebook.presto.tests.functions.MapAggregateTests.testSimpleHistogramInt(MapAggregateTests.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

mattsfuller avatar Sep 09 '15 17:09 mattsfuller

Here's my test:

package com.facebook.presto.tests.functions;

import com.google.common.collect.ImmutableMap;
import com.teradata.tempto.ProductTest;
import com.teradata.tempto.Requirement;
import com.teradata.tempto.RequirementsProvider;
import com.teradata.tempto.Requires;
import com.teradata.tempto.configuration.Configuration;
import com.teradata.tempto.fulfillment.table.ImmutableTableRequirement;
import com.teradata.tempto.query.QueryResult;
import org.testng.annotations.Test;

import static com.facebook.presto.tests.ImmutableTpchTablesRequirements.ImmutableNationTable;
import static com.facebook.presto.tests.ImmutableTpchTablesRequirements.ImmutableRegionTable;
import static com.facebook.presto.tests.TestGroups.AGGREGATE_FUNCTIONS;
import static com.google.common.collect.Maps.newHashMap;
import static com.teradata.tempto.assertions.QueryAssert.Row.row;
import static com.teradata.tempto.assertions.QueryAssert.assertThat;
import static com.teradata.tempto.query.QueryExecutor.query;

import static com.teradata.tempto.fulfillment.table.hive.tpch.TpchTableDefinitions.NATION;
import static com.teradata.tempto.fulfillment.table.hive.tpch.TpchTableDefinitions.REGION;

import static com.teradata.tempto.Requirements.compose;

public class MapAggregateTests
    extends ProductTest
{

    private static class MapAggregateTestRequirements
            implements RequirementsProvider
    {
        public static final Requirement NATION_TABLE = new ImmutableTableRequirement(NATION);
        public static final Requirement REGION_TABLE = new ImmutableTableRequirement(REGION);

        @Override
        public Requirement getRequirements(Configuration configuration)
        {
            return compose(
                    NATION_TABLE,
                    REGION_TABLE
            );
        }
    }


    @Test(groups = AGGREGATE_FUNCTIONS)
    @Requires(MapAggregateTestRequirements.class)
    public void testSimpleHistogramInt()
    {
        QueryResult queryResult = query("select histogram(n_regionkey) from nation");
        assertThat(queryResult).containsExactly(row(newHashMap(ImmutableMap.of(0, 5, 1, 5, 2, 5, 3, 5, 4, 5))));
    }

    @Test(groups = AGGREGATE_FUNCTIONS)
    @Requires(MapAggregateTestRequirements.class)
        public void testSimpleHistogramString()
    {
        QueryResult queryResult = query("select histogram(region.r_name) from region, nation where region.r_regionkey=nation.n_regionkey");
        assertThat(queryResult).containsExactly(row(newHashMap(ImmutableMap.of("EUROPE", 5, "AFRICA", 5, "AMERICA", 5, "ASIA", 5, "MIDDLE EAST", 5))));
    }

}

mattsfuller avatar Sep 09 '15 17:09 mattsfuller