I'm trying to create a Materialized View to optimize comsuption of data. I want the view to show just the registers of the day, but when I try to use functions like CURRENT_DATE it shows the error message "Materialized view query cannot use functions that depend on current time (example: CURRENT_TIMESTAMP, CURRENT_DATE)."
I tried to use some custom functions and to use a select on the filter to get the last ocurrance (as this table has a big flux of data) both without sucess, as it returns the message "The incremental materialized view query contains an unsupported feature. This may be caused by having an expression on top of the grouping keys or aggregated values."
-- CURRENT_DATE
CREATE MATERIALIZED VIEW `myProjectId.mydataSet.statistics_mv` AS
SELECT
_id,
column1,
DATA_STATISTICS
...
FROM
`myProjectId.mydataSet.mytable`
WHERE CAST(DATA_STATISTICS AS DATE) > CURRENT_DATE('America/Sao_Paulo')
-- SELECT ON FILTER
CREATE MATERIALIZED VIEW `myProjectId.mydataSet.statistics_mv` AS
SELECT
_id,
column1,
DATA_STATISTICS
...
FROM
`myProjectId.mydataSet.mytable`
WHERE DATA_STATISTICS = (
SELECT DATA_STATISTICS
FROM `statistics-homolog.MultAutomovel.raw`
ORDER BY DATA_STATISTICS DESC
LIMIT 1
)
Any sugestion how to do it?
In BigQuery, materialized views are precomputed views that periodically cache the results of a query for increased performance and efficiency. [Ref: https://cloud.google.com/bigquery/docs/materialized-views-intro]
If you have any dynamic keywords (like current date, current timestamp) in the view definition then GBQ can not handle the refresh rate, so those are not allowed.
If you do not need the "materialized" reason for the view, then you can get away with this:
e.g.
I do not know more context of this requirement of yours but to go ahead maybe you can look into: either just staying with a standard view or a stored procedure or some other programmatic way of sending the current date to a block of SQL.