Search in sources :

Example 11 with SQLDimensionProjection

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection in project elide by yahoo.

the class JoinJoinTable method test3TableJoinWithoutLogicalColumn.

// Case:
// dim3 -> {{join.joinjoin.dim2}}
// {{join.joinjoin.dim2}} -> {{join.joinjoin.dim3}}
// {{join.joinjoin.dim3}} -> Physical
@Test
void test3TableJoinWithoutLogicalColumn() {
    SQLDimensionProjection dim3 = (SQLDimensionProjection) table.getDimensionProjection("dim3");
    Query query = Query.builder().source(table).dimensionProjection(dim3).arguments(queryArgs).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join_258525107_joinjoin_88940112`.`dim3` - 'tableArgValue' AS `dim3` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join_258525107` " + NL + "ON " + NL + "  `MainTable`.`id` = `MainTable_join_258525107`.`id` " + NL + "LEFT OUTER JOIN " + NL + "  `joinjoin_table` AS `MainTable_join_258525107_joinjoin_88940112` " + NL + "ON " + NL + "  `MainTable_join_258525107`.`id` = `MainTable_join_258525107_joinjoin_88940112`.`id` ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

Example 12 with SQLDimensionProjection

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection in project elide by yahoo.

the class PhysicalRefColumnContextTest method testLogicalReference.

@Test
public void testLogicalReference() {
    Map<String, Argument> impressionsArg = new HashMap<>();
    impressionsArg.put("aggregation", Argument.builder().name("aggregation").value("SUM").build());
    SQLMetricProjection impressions = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressions", "impressions", impressionsArg);
    Map<String, Argument> testImpressionsArg = new HashMap<>();
    testImpressionsArg.put("aggregation", Argument.builder().name("aggregation").value("MIN").build());
    SQLMetricProjection testImpressions = (SQLMetricProjection) revenueFactTable.getMetricProjection("testImpressions", "testImpressions", testImpressionsArg);
    SQLMetricProjection testRevenue = (SQLMetricProjection) revenueFactTable.getMetricProjection("testRevenue");
    SQLMetricProjection testRevenueLogicalRef = (SQLMetricProjection) revenueFactTable.getMetricProjection("testRevenueLogicalRef");
    Map<String, Argument> revenueArg = new HashMap<>();
    revenueArg.put("format", Argument.builder().name("format").value("11D00").build());
    SQLMetricProjection revenueWithArg = (SQLMetricProjection) revenueFactTable.getMetricProjection("revenue", "revenueWithArg", revenueArg);
    SQLDimensionProjection conversionRate = (SQLDimensionProjection) revenueFactTable.getDimensionProjection("conversionRate");
    SQLDimensionProjection rateProvider = (SQLDimensionProjection) revenueFactTable.getDimensionProjection("rateProvider");
    Query query = Query.builder().source(revenueFactTable).metricProjection(impressions).metricProjection(testImpressions).metricProjection(testRevenue).metricProjection(testRevenueLogicalRef).metricProjection(revenueWithArg).dimensionProjection(conversionRate).dimensionProjection(rateProvider).arguments(queryArgs).build();
    Query.QueryBuilder builder = Query.builder().source(query.getSource()).metricProjections(query.getMetricProjections()).dimensionProjections(query.getDimensionProjections()).arguments(query.getArguments());
    Query expandedQuery = addHiddenProjections(metaDataStore, builder, query).build();
    // definition: {{$$column.args.aggregation}}({{$impressions}})
    // -> value of 'aggregation' argument is passed in the query for "impressions" column and same is used while
    // resolving this column.
    assertEquals("SUM({{$impressions}})", impressions.toPhysicalReferences(expandedQuery, metaDataStore));
    // definition: {{impressions}}) * {{$$table.args.testPercentage}}
    // -> default value of table argument 'testPercentage' is used.
    // -> value of 'aggregation' argument is passed in the query for "testImpressions" column and same is used while
    // resolving referenced column "impressions".
    assertEquals("MIN({{$impressions}})) * 0.1", testImpressions.toPhysicalReferences(expandedQuery, metaDataStore));
    // definition: {{revenue}}
    // revenue definition: TO_CHAR(SUM({{$revenue}}) * {{rate.conversionRate}}, {{$$column.args.format}})
    // -> default value of 'format' argument in "revenue" column is used while resolving this column.
    // -> default value of 'format' argument in "revenue" column is passed to joined table's "conversionRate" column.
    assertEquals("TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 99D00), 99D00)", testRevenue.toPhysicalReferences(expandedQuery, metaDataStore));
    // definition: {{revenueUsingLogicalRef}}
    // revenueUsingLogicalRef's definition: TO_CHAR(SUM({{$revenue}}) * {{conversionRate}}, {{$$column.args.format}})
    // -> default value of 'format' argument in "revenueUsingLogicalRef" column is used while resolving this column.
    // -> This column references "conversionRate" which references "rate.conversionRate". Since conversionRate doesn't have
    // 'format' argument defined, default value of 'format' argument in joined table's "conversionRate" column is used.
    assertEquals("TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 9D0), 99D00)", testRevenueLogicalRef.toPhysicalReferences(expandedQuery, metaDataStore));
    // definition: TO_CHAR(SUM({{$revenue}}) * {{rate.conversionRate}}, {{$$column.args.format}})
    // -> value of 'format' argument is passed in the query for "revenue" column and same is used for resolving
    // referenced column "rate.conversionRate" and this column.
    assertEquals("TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 11D00), 11D00)", revenueWithArg.toPhysicalReferences(expandedQuery, metaDataStore));
    // definition: {{rate.conversionRate}}
    // -> logical column 'conversionRate' doesn't support arguments.
    // -> default value of 'format' argument in "conversionRate" column of joined table is used while resolving this.
    assertEquals("TO_CHAR({{rate.$conversion_rate}}, 9D0)", conversionRate.toPhysicalReferences(expandedQuery, metaDataStore));
    // definition: {{rate.$provider}}
    assertEquals("{{rate.$provider}}", rateProvider.toPhysicalReferences(expandedQuery, metaDataStore));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) SQLMetricProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection) Test(org.junit.jupiter.api.Test)

Aggregations

Query (com.yahoo.elide.datastores.aggregation.query.Query)12 SQLDimensionProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection)12 Test (org.junit.jupiter.api.Test)12 ToString (lombok.ToString)11 Argument (com.yahoo.elide.core.request.Argument)9 HashMap (java.util.HashMap)9 SQLMetricProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection)2