.collect(Collectors.joining(" union all ")), dimension.isPresent() ? ", 2" : ""); } else { String collection = retentionAction.get().collection(); retentionAction.get().filter(), missingPreComputedTables, dimension.isPresent(), timezone); metastore.getCollection(project, collection).stream().anyMatch(e -> e.getName().equals("_device_id")), collection, connectorField, Optional.empty(), timeColumn, dimension, startDate, endDate, retentionAction.get().filter()), dimension.isPresent() ? ", 2" : "");
@JsonProperty public static String getFilter() { return getFilter().toString(); }
dimension.map(e -> "," + e).orElse(""), project, ValidationUtil.checkCollection(action.collection(), '`'), action.filter().map(f -> "WHERE " + formatExpression(f)).orElse(""))) .orElseGet(() -> metastore.getCollectionNames(project).stream() .map(collection -> format("SELECT `$date`, _user, _time %s FROM %s.%s",
.collect(Collectors.joining(" union all ")); } else { String collection = retentionAction.get().collection(); connectorField, dimension, timePredicate, retentionAction.get().filter());
@Test public void testFilter() throws Exception { QueryResult result = getRetentionQueryExecutor().query(CONTEXT, Optional.of(RetentionAction.create("test0", Optional.of("teststr = 'test0'"))), Optional.of(RetentionAction.create("test1", Optional.of("teststr = 'test0'"))), DAY, Optional.empty(), Optional.of(15), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC, false) .getResult().join(); assertFalse(result.isFailed()); assertEquals(result.getResult(), of( asList(LocalDate.parse("1970-01-01"), null, 1L), asList(LocalDate.parse("1970-01-01"), 1L, 1L), asList(LocalDate.parse("1970-01-03"), null, 1L))); }
@Test public void testDifferentCollections() throws Exception { QueryResult result = getRetentionQueryExecutor().query(CONTEXT, Optional.of(RetentionAction.create("test0", Optional.empty())), Optional.of(RetentionAction.create("test1", Optional.empty())), DAY, Optional.empty(), Optional.of(15), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC, false) .getResult().join(); assertFalse(result.isFailed()); assertEquals(result.getResult(), of( asList(LocalDate.parse("1970-01-01"), null, 1L), asList(LocalDate.parse("1970-01-01"), 1L, 1L), asList(LocalDate.parse("1970-01-02"), null, 1L), asList(LocalDate.parse("1970-01-03"), null, 1L))); }
@Test public void testDimension() throws Exception { QueryResult result = getRetentionQueryExecutor().query(CONTEXT, Optional.of(RetentionAction.create("test0", Optional.empty())), Optional.of(RetentionAction.create("test1", Optional.empty())), DAY, Optional.of("teststr"), Optional.of(15), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC, false).getResult().join(); assertFalse(result.isFailed()); assertEquals(ImmutableSet.copyOf(result.getResult()), ImmutableSet.of( asList("test0", null, 1L), asList("test0", 1L, 1L), asList("test1", null, 1L))); }
protected boolean testDeviceIdExists(Optional<RetentionAction> firstAction, Map<String, List<SchemaField>> collections) { if (firstAction.isPresent()) { List<SchemaField> schemaFields = collections.get(firstAction.get().collection()); if (schemaFields == null) { throw new RakamException("The collection in first action does not exist.", HttpResponseStatus.BAD_REQUEST); } return schemaFields.stream().anyMatch(e -> e.getName().equals("_device_id")); } else { return collections.entrySet().stream() .allMatch(e -> e.getValue().stream().anyMatch(field -> field.getName().equals("_device_id"))); } } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof RetentionQueryExecutor.RetentionAction) { RetentionQueryExecutor.RetentionAction that = (RetentionQueryExecutor.RetentionAction) o; return (this.collection.equals(that.collection())) && (this.filter.equals(that.filter())); } return false; }