@Override public QueryExecution export( RequestContext context, List<String> collections, Measure measure, Reference grouping, Reference segmentValue2, String filterExpression, LocalDate startDate, LocalDate endDate, ZoneId timezone) { return analyzeInternal(context, collections, measure, grouping, segmentValue2, filterExpression, startDate, endDate, timezone, false); }
private boolean testFilterExpressionForPerComputedTable(Expression filterExp, OLAPTable options) { final boolean[] columnExists = {true}; new DefaultExpressionTraversalVisitor<Void, Void>() { @Override protected Void visitIdentifier(Identifier node, Void context) { if (!options.dimensions.contains(node.getValue())) { columnExists[0] = false; } return null; } }.process(filterExp, null); return columnExists[0]; }
public String convertSqlFunction(AggregationType intermediate, AggregationType main) { return convertSqlFunction(intermediate); }
checkReference(grouping.value, startDate, endDate, collections.size()); checkReference(segment.value, startDate, endDate, collections.size()); && (grouping == null || (grouping.type == REFERENCE || (grouping.type == COLUMN && options.dimensions.contains(grouping.value)))) && (segment == null || (segment.value.equals("_collection") && segment.type == COLUMN && options.collections.size() == 1) || (segment.type == REFERENCE || (segment.type == COLUMN && options.dimensions.contains(segment.value)))) && (filterExp == null || testFilterExpressionForPerComputedTable(filterExp, options))) { return true; grouping != null ? (getColumnValue(timestampMapping, grouping, true) + " as " + checkTableColumn(getColumnReference(grouping) + "_group") + " ,") : "", segment != null ? (getColumnValue(timestampMapping, segment, true) + " as " + checkTableColumn(getColumnReference(segment) + "_segment") + " ,") : "", format(getFinalForAggregationFunction(measure), measure.column + "_" + measure.aggregation.name().toLowerCase()), preComputedTable.get().getValue(), Stream.of( String measureAgg = convertSqlFunction(measure != null && measure.aggregation != null ? measure.aggregation : COUNT); String measureColumn = measure != null && String select = generateComputeQuery(grouping, segment, collections.get(0)); computeQuery = format("select %s %s as value from %s where %s %s", select.isEmpty() ? select : select + ",", where, groupBy); } else { String selectPart = (grouping == null ? "" : checkTableColumn(getColumnReference(grouping) + "_group")) + (grouping == null ? "" : ", ") + checkTableColumn(getColumnReference(segment) + "_segment"); String select = generateComputeQuery(grouping, segment, collection);
if (buildConfigObject(EventExplorerConfig.class).isEventExplorerEnabled()) { binder.bind(EventExplorer.class).to(PostgresqlEventExplorer.class);
checkReference(timestampMapping, grouping.value, startDate, endDate, collections.size()); checkReference(timestampMapping, segment.value, startDate, endDate, collections.size()); new AbstractMap.SimpleEntry<>("group", grouping)).stream() .filter(e -> e != null) .map(e -> getColumnReference(e.getValue()) + "_" + e.getKey()) .collect(Collectors.joining(", ")); String groupBy = groups.isEmpty() ? "" : ("GROUP BY " + groups + " WITH TOTALS"); String selectPart = (grouping == null ? "" : checkTableColumn(getColumnReference(grouping) + "_group", '`')) + (grouping == null ? "" : ", ") + checkTableColumn(getColumnReference(segment) + "_segment", '`'); "%s\n" + ") ORDER BY %s DESC LIMIT 500", grouping == null ? "" : format(grouping.type == COLUMN ? checkTableColumn("%s_group", '`') : checkTableColumn("%s_group", '`'), getColumnReference(grouping)), segment == null ? "" : ((grouping == null ? "" : ",") + format(segment.type == COLUMN ? checkTableColumn("%s_segment", '`') : checkTableColumn("%s_segment", '`'), getColumnReference(segment))), grouping != null || segment != null ? "," : "", computeQuery, segment != null && grouping != null ? 3 : 2);
protected String generateComputeQuery(Reference grouping, Reference segment, String collection) { StringBuilder selectBuilder = new StringBuilder(); if (grouping != null) { selectBuilder.append(getColumnValue(timestampMapping, grouping, true) + " as " + checkTableColumn(getColumnReference(grouping) + "_group")); if (segment != null) { selectBuilder.append(", "); } } if (segment != null) { selectBuilder.append((!segment.equals(DEFAULT_SEGMENT) ? getColumnValue(timestampMapping, segment, true) : "'" + checkLiteral(collection) + "'") + " as " + checkTableColumn(getColumnReference(segment) + "_segment")); } return selectBuilder.toString(); }
checkReference(dimension.get(), startDate, endDate, collections.map(v -> v.size()).orElse(10)); format(timestampMapping.get(timestampTransformation), "_time"), aggregationMethod.get(), sourceTable(collections), timePredicate); } else { query = format("select collection, cast(coalesce(sum(total), 0) as bigint) as total \n" + " from (%s) data where %s group by 1", sourceTable(collections), timePredicate);
.map(agg -> getAggregationColumn(agg, table.aggregations).map(e -> format(e, column) + " as " + column + "_" + agg.name().toLowerCase())) .filter(Optional::isPresent).map(Optional::get).collect(Collectors.joining(", "))) .collect(Collectors.joining(", ")); .thenApply(v -> new PrecalculatedTable(name, table.tableName));
protected String generateComputeQuery(Reference grouping, Reference segment, String collection) { StringBuilder selectBuilder = new StringBuilder(); if (grouping != null) { selectBuilder.append(getColumnValue(grouping, true) + " as " + checkTableColumn(getColumnReference(grouping) + "_group", '`')); if (segment != null) { selectBuilder.append(", "); } } if (segment != null) { selectBuilder.append((!segment.equals(DEFAULT_SEGMENT) ? getColumnValue(segment, true) : "'" + stripName(collection, "collection") + "'") + " as " + checkTableColumn(getColumnReference(segment) + "_segment", '`')); } return selectBuilder.toString(); }
checkReference(timestampMapping, dimension.get(), startDate, endDate, collections.map(v -> v.size()).orElse(10));
private String getFinalForAggregationFunction(Measure aggregation) { switch (aggregation.aggregation) { case AVERAGE: return "cast(sum(%1$s) as double) / count(%1$s)"; case MAXIMUM: return "max(%s)"; case MINIMUM: return "min(%s)"; case COUNT: return "count(%s)"; case SUM: return "sum(%s)"; case COUNT_UNIQUE: throw new UnsupportedOperationException(); case APPROXIMATE_UNIQUE: return getFinalForApproximateUniqueFunction(); default: throw new IllegalArgumentException("aggregation type is not supported"); } }
private Optional<String> getAggregationColumn(AggregationType agg, Set<AggregationType> aggregations) { switch (agg) { case AVERAGE: aggregations.add(COUNT); aggregations.add(SUM); return Optional.empty(); case MAXIMUM: return Optional.of("max(%s)"); case MINIMUM: return Optional.of("min(%s)"); case COUNT: return Optional.of("count(%s)"); case SUM: return Optional.of("sum(%s)"); case COUNT_UNIQUE: throw new UnsupportedOperationException("Not supported yet."); case APPROXIMATE_UNIQUE: return Optional.of(getIntermediateForApproximateUniqueFunction()); default: throw new IllegalArgumentException("aggregation type is not supported"); } }
if (eventExplorerConfig.isEventExplorerEnabled()) { binder.bind(EventExplorer.class).to(PrestoEventExplorer.class);
@Override public QueryExecution analyze( RequestContext context, List<String> collections, Measure measure, Reference grouping, Reference segmentValue2, String filterExpression, LocalDate startDate, LocalDate endDate, ZoneId timezone) { return analyzeInternal(context, collections, measure, grouping, segmentValue2, filterExpression, startDate, endDate, timezone, true); }
private ActiveModuleList(UserPluginConfig userPluginConfig, boolean userStorageMailbox, RealTimeConfig realtimeConfig, EventStreamConfig eventStreamConfig, EventExplorerConfig eventExplorerConfig, UserPluginConfig userStorage, ProjectConfig projectConfig, boolean scheduledTasksEnabled, boolean webhookEnabled, boolean customDatabaseEnabled) { this.userStorage = userPluginConfig.isEnabled(); this.userMailbox = userStorageMailbox; this.funnelAnalysisEnabled = userPluginConfig.isFunnelAnalysisEnabled(); this.automationEnabled = userPluginConfig.getAutomationEnabled(); this.abTestingEnabled = userPluginConfig.getAbTestingEnabled(); this.retentionAnalysisEnabled = userPluginConfig.isRetentionAnalysisEnabled(); this.eventExplorer = eventExplorerConfig.isEventExplorerEnabled(); this.realtime = realtimeConfig.isRealtimeModuleEnabled(); this.eventStream = eventStreamConfig.getEventStreamEnabled(); this.userStorageEventFilter = userStorage.getStorageModule() != null; this.companyName = projectConfig.getCompanyName(); this.timeColumn = projectConfig.getTimeColumn(); this.userColumn = projectConfig.getUserColumn(); this.customDatabaseEnabled = customDatabaseEnabled; this.scheduledTasksEnabled = scheduledTasksEnabled; this.webhookEnabled = webhookEnabled; } }
.in(Scopes.SINGLETON); if (buildConfigObject(EventExplorerConfig.class).isEventExplorerEnabled()) { binder.bind(EventExplorer.class).to(ClickHouseEventExplorer.class);