Search in sources :

Example 6 with SQLDimensionProjection

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

the class CurrencyRate 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(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)", impressions.toSQL(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(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`impressions`)) * 0.1", testImpressions.toSQL(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(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 99D00), 99D00)", testRevenue.toSQL(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(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 9D0), 99D00)", testRevenueLogicalRef.toSQL(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(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact`.`revenue`)" + " * TO_CHAR(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 11D00), 11D00)", revenueWithArg.toSQL(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(`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`conversion_rate`, 9D0)", conversionRate.toSQL(expandedQuery, metaDataStore));
    // definition: {{rate.$provider}}
    assertEquals("`com_yahoo_elide_datastores_aggregation_metadata_RevenueFact_rate_221749474`.`provider`", rateProvider.toSQL(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) ToString(lombok.ToString) SQLMetricProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection) Test(org.junit.jupiter.api.Test)

Example 7 with SQLDimensionProjection

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

the class JoinJoinTable method test2TableJoin.

// Case:
// dim1 -> {{join.dim1}}
// {{join.dim1}} -> Physical
@Test
void test2TableJoin() {
    SQLDimensionProjection dim1 = (SQLDimensionProjection) table.getDimensionProjection("dim1");
    Query query = Query.builder().source(table).dimensionProjection(dim1).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join_258525107`.`dim1` AS `dim1` " + 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` ";
    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 8 with SQLDimensionProjection

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

the class JoinJoinTable method testArgumentsInJoinExprCase2a.

// dim4 and dim5 passes different value for join expression's argument 'exprArg'
// 2 Join expressions are generated.
@Test
void testArgumentsInJoinExprCase2a() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("value4").build());
    SQLDimensionProjection dim4 = (SQLDimensionProjection) table.getDimensionProjection("dim4", "dim4", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("value5").build());
    SQLDimensionProjection dim5 = (SQLDimensionProjection) table.getDimensionProjection("dim5", "dim5", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4).dimensionProjection(dim5).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2_63993339`.`dim1` AS `dim4`," + NL + "           `MainTable_join2_86115708`.`dim1` AS `dim5` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_63993339` " + NL + "ON " + NL + "  value = 'value4' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_63993339`.`dim4` - 'foo' " + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_86115708` " + NL + "ON " + NL + "  value = 'value5' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_86115708`.`dim4` - 'foo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
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) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

Example 9 with SQLDimensionProjection

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

the class JoinJoinTable method testArgumentsInJoinExprCase5b.

// dim4a and dim5a passes different value for join expression's argument 'exprArg'
// dim4a and dim5a passes different value for join table's column argument 'joinArg'
// 2 Join expressions are generated as 'exprArg' is different but fixed value of 'joinArg' is used.
@Test
void testArgumentsInJoinExprCase5b() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("value4").build());
    dim4Arg.put("joinArg", Argument.builder().name("joinArg").value("foo4").build());
    SQLDimensionProjection dim4a = (SQLDimensionProjection) table.getDimensionProjection("dim4a", "dim4a", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("value5").build());
    dim5Arg.put("joinArg", Argument.builder().name("joinArg").value("foo5").build());
    SQLDimensionProjection dim5a = (SQLDimensionProjection) table.getDimensionProjection("dim5a", "dim5a", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4a).dimensionProjection(dim5a).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2a_16142728`.`dim1` AS `dim4a`," + NL + "           `MainTable_join2a_29675529`.`dim1` AS `dim5a` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2a_16142728` " + NL + "ON " + NL + "  value = 'value4' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2a_16142728`.`dim4` - 'fixedFoo' " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2a_29675529` " + NL + "ON " + NL + "  value = 'value5' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2a_29675529`.`dim4` - 'fixedFoo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
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) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

Example 10 with SQLDimensionProjection

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

the class JoinJoinTable method test3TableJoinWithLogicalColumn.

// Case:
// dim -> {{join.dim2}}
// {{join.dim2}} -> {{join.dim3}}
// {{join.dim3}} -> {{joinjoin.dim3}}
// {{joinjoin.dim3}} -> Physical
@Test
void test3TableJoinWithLogicalColumn() {
    SQLDimensionProjection dim2 = (SQLDimensionProjection) table.getDimensionProjection("dim2");
    Query query = Query.builder().source(table).dimensionProjection(dim2).arguments(queryArgs).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join_258525107_joinjoin_88940112`.`dim3` - 'tableArgValue' AS `dim2` " + 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)

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