Consider the following code:
view: datetime {
derived_table: {
sql: SELECT CURRENT_DATETIME as dt;; # Bigquery dialect
}
dimension_group: dt {
type: time
timeframes: [
date,
month
]
sql: ${TABLE}.dt ;;
datatype: datetime
}
}
explore: datetime {}
This is supposed to be pretty straightforward - a dimension group with datetime as underlying data type.
Looker generates the following SQL:
WITH datetime AS (SELECT CURRENT_DATETIME as dt)
SELECT
CAST(TIMESTAMP(FORMAT_TIMESTAMP('%F %T', datetime.dt , 'Asia/Kolkata')) AS DATE) AS datetime_dt_date
FROM datetime
GROUP BY 1
Which produces an error as the underlying type is not timestamp.
Failed to retrieve data - No matching signature for function FORMAT_TIMESTAMP for argument types: STRING, DATETIME, STRING. Supported signature: FORMAT_TIMESTAMP(STRING, TIMESTAMP, [STRING]) at [4:24]
This happens with other datatypes too. There is a way to overcome it by casting the datetime to timestamp in the โsql:โ element but this is a hack and produces redundant transformation.
Is it a bug?
Solved! Go to Solution.
Youโll be pleased to know (especially @vfx1) that weโve just fixed this issue. It should be present in the next version of Looker.
Weโll be introducing a legacy feature flag as well as a model-level keyword parameter to control this, to make sure that folks can get the proper experience without breaking any code that has been relying on this incorrect behavior.
Iโm being intentionally vague as thereโs still time for things to change, so keep your eyes peeled for the details in the release notes for 7.14!
I think this is just a discrepancy in nomenclature. โDatetimeโ in LookML represents a concept which may have different names in different SQL dialects.
On the other hand, the โdatetimeโ type in BigQuery is actually rather clunky and difficult to work with - it represents a local time with no timezone information, which is (in my experience) not so useful in practice. is there a reason youโre not using a BigQuery timestamp instead?
Looking at our docs a bit more, I guess we have LookML datatypes of both datetime and timestamp. I think Iโll have to read into it a bit more!
Hi Fabio,
Thanks for taking the time to look at this. The reason why we are using DATETIME datatype is because the underlying Bigquery tables use fields of this type and they come from the original data sources.
Of course DATETIME fields can be converted back to timestamp while creating the views in Looker but then what is the use for the โdatatypeโ parameter if it has to be converted to TIMESTAMP?
On a side note, the automatic conversion to TIMESTAMP (by using create view from table) also doesnโt seem to work properly with timezones, so I reported this separately as a potential bug here.
Cheers
I found more details.
The documentation mentions at least at two places that for dimension_group
of type time
the default datatype
is datetime
.
By observing how looker writes SQL it seems the assumed default type (at least for BigQuery) is in fact timestamp
. And even if datatype
parameter is specified to be datetime
itโs being ignored, which produces invalid SQL.
Guys,
I was just wondering if there is some progress on this. It seems somewhat foundational to meโฆ
I think youโre right and that this is an issue with our default generated SQLโ Iโll pass it along to engineering!
Great news! Thanks!
Hi Izzy,
Is there some news about this?
Hi hi,
Our engineers agreed that this is something to be fixedโ Specifically, they thought it has to do with the way that bigquery treats the word โdatetimeโ. In a lot of dialects, itโs synonymous with timestamp, and we treat it as such. In BigQuery, though, it appears to be different, and thatโs the hitch.
Weโve prioritized it, but not urgently, since there is a workaround (casting) thatโs not too in depthโ Which is to say it will get fixed, but there are currently other projects prioritized higher in this development cycle.
This topic is linked to the bug, so Iโll know if thereโs any progress made and update here. Thanks for checking in!
Hi, the workaround works and isnโt too painful, but the bug isnโt very obvious and puzzled me for quite a while. So itโd be nice to have a fix.
Cheers,
Alex
A fix will definitely come, since itโs been triaged & prioritized by engineering. Itโs just a matter of when, or if there are other things in the queue ahead of it. Thanks for checking in on it! Iโll drop a line where when itโs fixed.
Just adding a +1 in looking for a fix for this.
+1 From me as well!
As a bonus, you could do something like this:
TIMESTAMP(<datetime_column>, <database_timezone>)
(where <database_timezone> is the timezone specified in admin).
That way, youโd be enriching our datetime columns with timezone info! I think thatโs actually a great value add, as well as a fix for an annoying bug. ๐
I have found that when trying to create a time dimension group parameter based on a date type that is atypical (not based on a datetime field), the best way to overcome this issue is to apply a datatype parameter as such:
dimension_group: created {
type: time
**datatype: date**
timeframes: [
raw,
time,
date,
week,
month,
quarter,
year
]
sql: ${TABLE}._created_date ;;
}
This alleviates the error above.
Hi Kate,
It goes half way there ๐ Doing the above makes looker to write the following:
CAST(CAST(<some_datetime> AS TIMESTAMP) AS DATE)
Itโs great as:
Itโs not so great as:
So all in all - doesnโt seem to be a workaround for the issue.
Youโll be pleased to know (especially @vfx1) that weโve just fixed this issue. It should be present in the next version of Looker.
Weโll be introducing a legacy feature flag as well as a model-level keyword parameter to control this, to make sure that folks can get the proper experience without breaking any code that has been relying on this incorrect behavior.
Iโm being intentionally vague as thereโs still time for things to change, so keep your eyes peeled for the details in the release notes for 7.14!
This was the only thread I could find with any mention of 7.14 at this time, so Iโm hijacking it just to ask @izzymiller if you know when the 7.14 relnotes will be published to https://docs.looker.com/relnotes
Itโs July 30th which is the expected final release date for 7.12; but there are fixes weโve been informed of in 7.14 that weโd love to see the published details of.
@izzymiller didnโt see this feature in 7.14. Am I missing it or did it get bumped to the next release? Thanks!
@Jason_Comp_Thre . This was indeed addressed in 7.14. See the changelog here:
Fixed: Incorrect SQL for
datetime
fields for BigQuery dialects is no longer being generated.