use of com.yahoo.elide.datastores.aggregation.metadata.models.Table in project elide by yahoo.
the class AggregationDataStore method validateModelExpressionChecks.
/**
* Validates The security Check expression type for both Table and all its fields.
* Table Security Check Condition - User Checks and Filter Expression Checks
* Field Security Check Condition - User Checks
* @param dictionary - Entity Dictionary
* @param clz - Model Type.
*/
private void validateModelExpressionChecks(EntityDictionary dictionary, Type<?> clz) {
PermissionExpressionVisitor visitor = new PermissionExpressionVisitor();
ParseTree parseTree = dictionary.getPermissionsForClass(clz, ReadPermission.class);
if (parseTree != null) {
validateExpression(dictionary, visitor.visit(parseTree), (checkClass) -> UserCheck.class.isAssignableFrom(checkClass) || FilterExpressionCheck.class.isAssignableFrom(checkClass), "Table Can only have User Check and Filter Expression Check." + "Operation Checks Not allowed. given - %s");
}
dictionary.getAllExposedFields(clz).stream().map(field -> dictionary.getPermissionsForField(clz, field, ReadPermission.class)).filter(Objects::nonNull).forEach(tree -> validateExpression(dictionary, visitor.visit(tree), (checkClass) -> UserCheck.class.isAssignableFrom(checkClass), "Fields Can only have User checks. Given - %s"));
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Table in project elide by yahoo.
the class AggregationDataStoreTransaction method buildQuery.
@VisibleForTesting
Query buildQuery(EntityProjection entityProjection, RequestScope scope) {
Table table = metaDataStore.getTable(scope.getDictionary().getJsonAliasFor(entityProjection.getType()), scope.getApiVersion());
String bypassCacheStr = scope.getRequestHeaderByName("bypasscache");
Boolean bypassCache = "true".equals(bypassCacheStr);
EntityProjectionTranslator translator = new EntityProjectionTranslator(queryEngine, table, entityProjection, scope, bypassCache);
Query query = translator.getQuery();
Query modifiedQuery = addTableFilterArguments(table, query, scope.getDictionary());
modifiedQuery = addColumnFilterArguments(table, modifiedQuery, scope.getDictionary());
return modifiedQuery;
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Table in project elide by yahoo.
the class AggregationDataStoreTransaction method loadObjects.
@Override
public <T> DataStoreIterable<T> loadObjects(EntityProjection entityProjection, RequestScope scope) {
QueryResult result = null;
QueryResponse response = null;
String cacheKey = null;
try {
// Convert multivalued map to map.
Map<String, String> headers = scope.getRequestHeaders().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, (entry) -> entry.getValue().stream().collect(Collectors.joining(" "))));
queryLogger.acceptQuery(scope.getRequestId(), scope.getUser(), headers, scope.getApiVersion(), scope.getQueryParams(), scope.getPath());
Query query = buildQuery(entityProjection, scope);
Table table = (Table) query.getSource();
if (cache != null && !query.isBypassingCache()) {
String tableVersion = queryEngine.getTableVersion(table, queryEngineTransaction);
tableVersion = tableVersion == null ? "" : tableVersion;
cacheKey = tableVersion + ';' + QueryKeyExtractor.extractKey(query);
result = cache.get(cacheKey);
}
boolean isCached = result != null;
List<String> queryText = queryEngine.explain(query);
queryLogger.processQuery(scope.getRequestId(), query, queryText, isCached);
if (result == null) {
result = queryEngine.executeQuery(query, queryEngineTransaction);
if (cacheKey != null) {
// The query result needs to be streamed into an in memory list before caching.
// TODO - add a cap to how many records can be streamed back. If this is exceeded, abort caching
// and return the results.
QueryResult cacheableResult = QueryResult.builder().data(Lists.newArrayList(result.getData().iterator())).pageTotals(result.getPageTotals()).build();
cache.put(cacheKey, cacheableResult);
result = cacheableResult;
}
}
if (entityProjection.getPagination() != null && entityProjection.getPagination().returnPageTotals()) {
entityProjection.getPagination().setPageTotals(result.getPageTotals());
}
response = new QueryResponse(HttpStatus.SC_OK, result.getData(), null);
return new DataStoreIterableBuilder(result.getData()).build();
} catch (HttpStatusException e) {
response = new QueryResponse(e.getStatus(), null, e.getMessage());
throw e;
} catch (Exception e) {
response = new QueryResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, null, e.getMessage());
throw e;
} finally {
queryLogger.completeQuery(scope.getRequestId(), response);
}
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Table in project elide by yahoo.
the class MetaDataStoreTest method testHiddenFields.
@Test
public void testHiddenFields() {
Table playerStats = dataStore.getTable(ClassType.of(PlayerStats.class));
Dimension country = playerStats.getDimension("country");
Dimension playerRank = playerStats.getDimension("playerRank");
Metric highScore = playerStats.getMetric("highScore");
Metric hiddenHighScore = playerStats.getMetric("hiddenHighScore");
TimeDimension recordedDate = playerStats.getTimeDimension("recordedDate");
TimeDimension hiddenRecordedDate = playerStats.getTimeDimension("hiddenRecordedDate");
assertTrue(country.isHidden());
assertFalse(playerRank.isHidden());
assertTrue(hiddenHighScore.isHidden());
assertFalse(highScore.isHidden());
assertTrue(hiddenRecordedDate.isHidden());
assertFalse(recordedDate.isHidden());
assertTrue(playerStats.getColumns().contains(highScore));
assertTrue(playerStats.getColumns().contains(recordedDate));
assertTrue(playerStats.getColumns().contains(playerRank));
assertFalse(playerStats.getColumns().contains(country));
assertFalse(playerStats.getColumns().contains(hiddenHighScore));
assertFalse(playerStats.getColumns().contains(hiddenRecordedDate));
assertTrue(playerStats.getAllColumns().contains(highScore));
assertTrue(playerStats.getAllColumns().contains(recordedDate));
assertTrue(playerStats.getAllColumns().contains(playerRank));
assertTrue(playerStats.getAllColumns().contains(country));
assertTrue(playerStats.getAllColumns().contains(hiddenHighScore));
assertTrue(playerStats.getAllColumns().contains(hiddenRecordedDate));
assertFalse(playerStats.getDimensions().contains(country));
assertFalse(playerStats.getMetrics().contains(hiddenHighScore));
assertFalse(playerStats.getTimeDimensions().contains(hiddenRecordedDate));
assertTrue(playerStats.getMetrics().contains(highScore));
assertTrue(playerStats.getDimensions().contains(playerRank));
assertTrue(playerStats.getTimeDimensions().contains(recordedDate));
assertTrue(playerStats.getAllDimensions().contains(country));
assertTrue(playerStats.getAllMetrics().contains(hiddenHighScore));
assertTrue(playerStats.getAllTimeDimensions().contains(hiddenRecordedDate));
assertTrue(playerStats.getAllMetrics().contains(highScore));
assertTrue(playerStats.getAllDimensions().contains(playerRank));
assertTrue(playerStats.getAllTimeDimensions().contains(recordedDate));
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Table in project elide by yahoo.
the class MetaDataStoreTest method testHiddenTable.
@Test
public void testHiddenTable() {
Table player = dataStore.getTable(ClassType.of(Player.class));
Table playerStats = dataStore.getTable(ClassType.of(PlayerStats.class));
assertTrue(player.isHidden());
assertFalse(playerStats.isHidden());
Namespace namespace = dataStore.getNamespace(ClassType.of(Player.class));
assertTrue(namespace.getTables().contains(playerStats));
assertFalse(namespace.getTables().contains(player));
}
Aggregations