Skip to content

Commit

Permalink
Remove usage of SQLReferenceTable. (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi-aga authored May 21, 2021
1 parent e1f90ce commit 4b8310f
Show file tree
Hide file tree
Showing 23 changed files with 158 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void validateModelExpressionChecks(EntityDictionary dictionary, Type<?>
}

/**
* Validates the Expression Check class to check whether it complies with the given predicate
* Validates the Expression Check class to check whether it complies with the given predicate.
* @param dictionary - Entity dictionary
* @param expressionChecksIdentifiers - Set of identifiers for whose the security check class is validated
* @param validCheckPredicate - Predicate that takes security check class as argument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import static com.yahoo.elide.core.request.Argument.getArgumentMapFromString;
import static com.yahoo.elide.core.utils.TypeHelper.appendAlias;
import static com.yahoo.elide.datastores.aggregation.query.ColumnProjection.createSafeAlias;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.PERIOD;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.applyQuotes;
import static java.util.Collections.emptyMap;
import static org.apache.commons.lang3.StringUtils.isBlank;

import com.yahoo.elide.core.request.Argument;
import com.yahoo.elide.datastores.aggregation.query.ColumnProjection;
import com.yahoo.elide.datastores.aggregation.query.Queryable;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLJoin;

import com.github.jknack.handlebars.EscapingStrategy;
import com.github.jknack.handlebars.Formatter;
import com.github.jknack.handlebars.Handlebars;
Expand Down Expand Up @@ -46,6 +46,7 @@ public class ColumnContext extends HashMap<String, Object> {
public static final String TBL_PREFIX = "$$table";
public static final String ARGS_KEY = "args";
public static final String EXPR_KEY = "expr";
public static final String PERIOD = ".";

protected final MetaDataStore metaDataStore;
protected final Queryable queryable;
Expand Down Expand Up @@ -250,4 +251,35 @@ public static Map<String, Argument> mergedArgumentMap(Map<String, Argument> refe
Map<String, Argument> callingObjectArgs) {
return mergedArgumentMap(referencedObjectArgs, callingObjectArgs, emptyMap());
}

/**
* Split a string on ".", append quotes around each split and join it back.
* eg: game.order_details to `game`.`order_details` .
*
* @param str column name / alias
* @param beginQuote prefix char
* @param endQuote suffix char
* @return quoted string
*/
private static String applyQuotes(String str, char beginQuote, char endQuote) {
if (isBlank(str)) {
return str;
}
if (str.contains(PERIOD)) {
return beginQuote + str.trim().replace(PERIOD, endQuote + PERIOD + beginQuote) + endQuote;
}
return beginQuote + str.trim() + endQuote;
}

/**
* Split a string on ".", append quotes around each split and join it back.
* eg: game.order_details to `game`.`order_details` .
*
* @param str column name / alias
* @param dialect Elide SQL dialect
* @return quoted string
*/
public static String applyQuotes(String str, SQLDialect dialect) {
return applyQuotes(str, dialect.getBeginQuote(), dialect.getEndQuote());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package com.yahoo.elide.datastores.aggregation.metadata;

import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.PERIOD;
import static org.apache.commons.lang3.StringUtils.isBlank;

import com.yahoo.elide.core.request.Argument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package com.yahoo.elide.datastores.aggregation.query;

import com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable;

/**
* Optimizes query plans.
*/
Expand All @@ -31,12 +29,12 @@ default String negateHint() {
* Verifies if this optimizer can execute on the given query.
* @return True if the query can be optimized by this optimizer.
*/
boolean canOptimize(Query query, SQLReferenceTable referenceTable);
boolean canOptimize(Query query);

/**
* Optimizes the query.
* @param query The query to optimize.
* @return A new optimized query.
*/
Query optimize(Query query, SQLReferenceTable referenceTable);
Query optimize(Query query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ default SQLDialect getDialect() {
}

/**
* Converts a filter expression into a set of ColumnProjections
* Converts a filter expression into a set of ColumnProjections.
* @param query The parent query.
* @param expression The filter expression to extract.
* @return A set of zero or more column projections with their arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.VersionQuery;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.DynamicSQLReferenceTable;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery;
import com.yahoo.elide.datastores.aggregation.queryengines.sql.query.QueryPlanTranslator;
Expand Down Expand Up @@ -77,7 +75,6 @@
public class SQLQueryEngine extends QueryEngine {

@Getter
private final SQLReferenceTable referenceTable;
private final ConnectionDetails defaultConnectionDetails;
private final Map<String, ConnectionDetails> connectionDetailsMap;
private final Set<Optimizer> optimizers;
Expand Down Expand Up @@ -115,7 +112,6 @@ public SQLQueryEngine(
this.formulaValidator = new FormulaValidator(metaDataStore);
this.metadataDictionary = metaDataStore.getMetadataDictionary();
populateMetaData(metaDataStore);
this.referenceTable = new SQLReferenceTable(metaDataStore);
this.optimizers = optimizers;
}

Expand Down Expand Up @@ -408,14 +404,13 @@ private Query expandMetricQueryPlans(Query query) {
}
}

QueryPlanTranslator queryPlanTranslator = new QueryPlanTranslator(query, referenceTable);
QueryPlanTranslator queryPlanTranslator = new QueryPlanTranslator(query, metaDataStore);

Query merged = (mergedPlan == null)
? QueryPlanTranslator.addHiddenProjections(referenceTable, query).build()
? QueryPlanTranslator.addHiddenProjections(metaDataStore, query).build()
: queryPlanTranslator.translate(mergedPlan);

for (Optimizer optimizer : optimizers) {
SQLReferenceTable queryReferenceTable = new DynamicSQLReferenceTable(referenceTable, merged);
SQLTable table = (SQLTable) query.getSource();

//TODO - support hints in table joins & query header. Query Header hints override join hints which
Expand All @@ -428,8 +423,8 @@ private Query expandMetricQueryPlans(Query query) {
continue;
}

if (optimizer.canOptimize(merged, queryReferenceTable)) {
merged = optimizer.optimize(merged, queryReferenceTable);
if (optimizer.canOptimize(merged)) {
merged = optimizer.optimize(merged);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package com.yahoo.elide.datastores.aggregation.queryengines.sql.expression;

import static com.yahoo.elide.core.request.Argument.getArgumentMapFromString;
import static com.yahoo.elide.datastores.aggregation.metadata.ColumnContext.PERIOD;
import static com.yahoo.elide.datastores.aggregation.metadata.ColumnContext.mergedArgumentMap;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.PERIOD;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import com.yahoo.elide.core.Path;
import com.yahoo.elide.core.dictionary.EntityDictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
package com.yahoo.elide.datastores.aggregation.queryengines.sql.expression;

import static com.yahoo.elide.core.utils.TypeHelper.appendAlias;
import static com.yahoo.elide.datastores.aggregation.metadata.ColumnContext.applyQuotes;
import static com.yahoo.elide.datastores.aggregation.metadata.ColumnContext.mergedArgumentMap;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.applyQuotes;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.hasSql;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLReferenceTable.resolveTableOrSubselect;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable.hasSql;
import static com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable.resolveTableOrSubselect;
import static java.util.Collections.emptySet;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import com.yahoo.elide.core.Path.PathElement;
Expand Down

This file was deleted.

Loading

0 comments on commit 4b8310f

Please sign in to comment.