Skip to content

Commit

Permalink
Fix 4616 generate series for PostgreSql (#4717)
Browse files Browse the repository at this point in the history
* add generate_series as a function

Use as a function

For example

SELECT generate_series(
    CAST('2023-09-01T00:00:00Z' AS TIMESTAMPTZ),
    CAST('2023-09-02T00:00:00Z' AS TIMESTAMPTZ),
    CAST('1 hour' AS INTERVAL)
  );

* Add integration test

assert that the timestamp series is generated
  • Loading branch information
griffio authored Oct 20, 2023
1 parent df707ce commit e40231b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeRes
-> IntermediateType(TEXT)
"json_array_length", "jsonb_array_length" -> IntermediateType(INTEGER)
"jsonb_path_exists", "jsonb_path_match", "jsonb_path_exists_tz", "jsonb_path_match_tz" -> IntermediateType(BOOLEAN)
"generate_series" -> encapsulatingType(exprList, INTEGER, BIG_INT, REAL, TIMESTAMP_TIMEZONE, TIMESTAMP)
else -> null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ stddev(foo),
regr_count(foo, bar)
FROM myTable
GROUP BY foo, bar;

selectGenerateSeries:
SELECT generate_series(
CAST(:start AS TIMESTAMPTZ),
CAST(:finish AS TIMESTAMPTZ),
CAST('1 hour' AS INTERVAL)
);
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,14 @@ class PostgreSqlTest {
assertThat(mul).isEqualTo(4.5)
}
}

@Test
fun testGenerateSeries() {
val start = OffsetDateTime.of(2023, 9, 1, 0, 0, 0, 0, ZoneOffset.ofHours(0))
val finish = OffsetDateTime.of(2023, 9, 1, 5, 0, 0, 0, ZoneOffset.ofHours(0))
val series = database.functionsQueries.selectGenerateSeries(start, finish).executeAsList()
assertThat(series.size).isEqualTo(6)
assertThat(series.first()).isEqualTo(start)
assertThat(series.last()).isEqualTo(finish)
}
}

0 comments on commit e40231b

Please sign in to comment.