Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions udfs/community/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ SELECT bqutil.fn.int(1.684)
* [cw_parse_timestamp](#cw_parse_timestamptimeString-string-formatString-string)
* [cw_period_intersection](#cw_period_intersectionp1-structlower-timestamp-upper-timestamp-p2-structlower-timestamp-upper-timestamp)
* [cw_period_ldiff](#cw_period_ldiffp1-structlower-timestamp-upper-timestamp-p2-structlower-timestamp-upper-timestamp)
* [cw_range_date_ldiff](#cw_range_date_ldiffp1-range-p2-range)
* [cw_range_datetime_ldiff](#cw_range_datetime_ldiffp1-range-p2-range)
* [cw_range_timestamp_ldiff](#cw_range_timestamp_ldiffp1-range-p2-range)
* [cw_period_rdiff](#cw_period_rdiffp1-structlower-timestamp-upper-timestamp-p2-structlower-timestamp-upper-timestamp)
* [cw_range_date_rdiff](#cw_range_date_rdiffp1-range-p2-range)
* [cw_range_datetime_rdiff](#cw_range_datetime_rdiffp1-range-p2-range)
* [cw_range_timestamp_rdiff](#cw_range_timestamp_rdiffp1-range-p2-range)
* [cw_regex_mode](#cw_regex_modemode-string)
* [cw_regexp_extract](#cw_regexp_extractstr-string-regexp-string)
* [cw_regexp_extract_all](#cw_regexp_extract_allstr-string-regexp-string)
Expand Down Expand Up @@ -784,6 +790,33 @@ SELECT bqutil.fn.cw_period_ldiff(
STRUCT(TIMESTAMP '2001-11-12 00:00:00' AS lower, TIMESTAMP '2001-11-13 00:00:00' AS upper)
```

### [cw_range_date_ldiff(p1 RANGE<DATE>, p2 RANGE<DATE>)](cw_range_date_ldiff.sqlx)
```sql
SELECT cw_udf.cw_range_date_ldiff(
RANGE(DATE '2001-11-12', DATE '2001-11-14'),
RANGE(DATE '2001-11-13', DATE '2001-11-15'))

RANGE(DATE '2001-11-12', DATE '2001-11-13')
```

### [cw_range_datetime_ldiff(p1 RANGE<DATETIME>, p2 RANGE<DATETIME>)](cw_range_datetime_ldiff.sqlx)
```sql
SELECT cw_udf.cw_range_datetime_ldiff(
RANGE(DATETIME '2001-11-12 00:00:00', DATETIME '2001-11-14 00:00:00'),
RANGE(DATETIME '2001-11-13 00:00:00', DATETIME '2001-11-15 00:00:00'))

RANGE(DATETIME '2001-11-12 00:00:00', DATETIME '2001-11-13 00:00:00')
```

### [cw_range_timestamp_ldiff(p1 RANGE<TIMESTAMP>, p2 RANGE<TIMESTAMP>)](cw_range_timestamp_ldiff.sqlx)
```sql
SELECT cw_udf.cw_range_timestamp_ldiff(
RANGE(TIMESTAMP '2001-11-12 00:00:00', TIMESTAMP '2001-11-14 00:00:00'),
RANGE(TIMESTAMP '2001-11-13 00:00:00', TIMESTAMP '2001-11-15 00:00:00'))

RANGE(TIMESTAMP '2001-11-12 00:00:00', TIMESTAMP '2001-11-13 00:00:00')
```

### [cw_period_rdiff(p1 STRUCT<lower TIMESTAMP, upper TIMESTAMP>, p2 STRUCT<lower TIMESTAMP, upper TIMESTAMP>)](cw_period_rdiff.sqlx)
```sql
SELECT bqutil.fn.cw_period_rdiff(
Expand All @@ -793,6 +826,34 @@ SELECT bqutil.fn.cw_period_rdiff(
STRUCT(TIMESTAMP '2001-11-14 00:00:00' AS lower, TIMESTAMP '2001-11-15 00:00:00' AS upper)
```

### [cw_range_date_rdiff(p1 RANGE<DATE>, p2 RANGE<DATE>)](cw_range_date_rdiff.sqlx)
```sql
SELECT cw_udf.cw_range_date_rdiff(
RANGE(DATE '2001-11-13', DATE '2001-11-15'),
RANGE(DATE '2001-11-12', DATE '2001-11-14'))

RANGE(DATE '2001-11-14', DATE '2001-11-15')
```

### [cw_range_datetime_rdiff(p1 RANGE<DATETIME>, p2 RANGE<DATETIME>)](cw_range_datetime_rdiff.sqlx)
```sql
SELECT cw_udf.cw_range_datetime_rdiff(
RANGE(DATETIME '2001-11-13 00:00:00', DATETIME '2001-11-15 00:00:00'),
RANGE(DATETIME '2001-11-12 00:00:00', DATETIME '2001-11-14 00:00:00'))

RANGE(DATETIME '2001-11-14 00:00:00', DATETIME '2001-11-15 00:00:00')
```


### [cw_range_timestamp_rdiff(p1 RANGE<TIMESTAMP>, p2 RANGE<TIMESTAMP>)](cw_range_timestamp_rdiff.sqlx)
```sql
SELECT cw_udf.cw_range_timestamp_rdiff(
RANGE(TIMESTAMP '2001-11-13 00:00:00', TIMESTAMP '2001-11-15 00:00:00'),
RANGE(TIMESTAMP '2001-11-12 00:00:00', TIMESTAMP '2001-11-14 00:00:00'))

RANGE(TIMESTAMP '2001-11-14 00:00:00', TIMESTAMP '2001-11-15 00:00:00')
```

### [cw_regex_mode(mode STRING)](cw_regex_mode.sqlx)
Retrieve mode.
```sql
Expand Down
26 changes: 26 additions & 0 deletions udfs/community/cw_range_date_ldiff.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config { hasOutput: true }
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(p1 RANGE<DATE>, p2 RANGE<DATE>) RETURNS RANGE<DATE>
OPTIONS(description="Emulates Teradata's LDIFF operator with RANGE<DATE> inputs.")
AS (
CASE
WHEN RANGE_OVERLAPS(p1, p2) AND RANGE_START(p1) < RANGE_START(p2) THEN
RANGE(RANGE_START(p1), RANGE_START(p2))
ELSE NULL
END
);
26 changes: 26 additions & 0 deletions udfs/community/cw_range_date_rdiff.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config { hasOutput: true }
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(p1 RANGE<DATE>, p2 RANGE<DATE>) RETURNS RANGE<DATE>
OPTIONS(description="Emulates Teradata's RDIFF operator with RANGE<DATE> inputs.")
AS (
CASE
WHEN RANGE_OVERLAPS(p1, p2) AND RANGE_END(p1) > RANGE_END(p2) THEN
RANGE(RANGE_END(p2), RANGE_END(p1))
ELSE NULL
END
);
26 changes: 26 additions & 0 deletions udfs/community/cw_range_datetime_ldiff.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config { hasOutput: true }
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(p1 RANGE<DATETIME>, p2 RANGE<DATETIME>) RETURNS RANGE<DATETIME>
OPTIONS(description="Emulates Teradata's LDIFF operator with RANGE<DATETIME> inputs.")
AS (
CASE
WHEN RANGE_OVERLAPS(p1, p2) AND RANGE_START(p1) < RANGE_START(p2) THEN
RANGE(RANGE_START(p1), RANGE_START(p2))
ELSE NULL
END
);
26 changes: 26 additions & 0 deletions udfs/community/cw_range_datetime_rdiff.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config { hasOutput: true }
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(p1 RANGE<DATETIME>, p2 RANGE<DATETIME>) RETURNS RANGE<DATETIME>
OPTIONS(description="Emulates Teradata's RDIFF operator with RANGE<DATETIME> inputs.")
AS (
CASE
WHEN RANGE_OVERLAPS(p1, p2) AND RANGE_END(p1) > RANGE_END(p2) THEN
RANGE(RANGE_END(p2), RANGE_END(p1))
ELSE NULL
END
);
26 changes: 26 additions & 0 deletions udfs/community/cw_range_timestamp_ldiff.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config { hasOutput: true }
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(p1 RANGE<TIMESTAMP>, p2 RANGE<TIMESTAMP>) RETURNS RANGE<TIMESTAMP>
OPTIONS(description="Emulates Teradata's LDIFF operator with RANGE<TIMESTAMP> inputs.")
AS (
CASE
WHEN RANGE_OVERLAPS(p1, p2) AND RANGE_START(p1) < RANGE_START(p2) THEN
RANGE(RANGE_START(p1), RANGE_START(p2))
ELSE NULL
END
);
26 changes: 26 additions & 0 deletions udfs/community/cw_range_timestamp_rdiff.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
config { hasOutput: true }
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

CREATE OR REPLACE FUNCTION ${self()}(p1 RANGE<TIMESTAMP>, p2 RANGE<TIMESTAMP>) RETURNS RANGE<TIMESTAMP>
OPTIONS(description="Emulates Teradata's RDIFF operator with RANGE<TIMESTAMP> inputs.")
AS (
CASE
WHEN RANGE_OVERLAPS(p1, p2) AND RANGE_END(p1) > RANGE_END(p2) THEN
RANGE(RANGE_END(p2), RANGE_END(p1))
ELSE NULL
END
);
Loading
Loading