Bigquery无法加载数据日期值或时间戳值格式错误

时间:2017-03-07 14:02:22

标签: google-bigquery bigtable bigdata

1.Error while uploading CSV , where Data format is '0000-00-00' &&  timestamp has '0000-00-00 00:00:00' value.
2.The Datatype is DATE, TIMESTAMP as Follows.

enter image description here
enter image description here 我错过任何忽略复选框。试图忽略所有错误,但不是加载所有数据bigquery忽略了日期格式行,只上传了允许的行。enter image description here

尝试使用空值,无法执行此操作,没有选择,将DATE替换为'1969-01-01',将Timestamp替换为'1969-01-01 00:00:00'。我能够上传数据。

enter image description here

2 个答案:

答案 0 :(得分:1)

有效日期的下限为0001-01-01; data types page提供了有关各种类型的有效范围的更多信息。一种选择是将值加载为STRING类型,然后应用SAFE_CAST(string_date_col AS DATE)等函数将值转换为DATE类型。例如,

#standardSQL
SELECT
  * EXCEPT(string_date_col, string_timestamp_col),
  SAFE_CAST(string_date_col AS DATE) AS date_col,
  SAFE_CAST(string_timestamp_col AS TIMESTAMP) AS timestamp_col 
FROM MyTableWithStrings;

作为一个独立的例子:

#standardSQL
WITH MyTableWithStrings AS (
  SELECT 1 AS x, '0000-00-00' AS string_date_col, '0000-00-00 00:00:00' AS string_timestamp_col UNION ALL
  SELECT 2 AS x, '2017-03-07' AS string_date_col, '2017-03-07 12:34:56' AS string_timestamp_col
)
SELECT
  * EXCEPT(string_date_col, string_timestamp_col),
  SAFE_CAST(string_date_col AS DATE) AS date_col,
  SAFE_CAST(string_timestamp_col AS TIMESTAMP) AS timestamp_col 
FROM MyTableWithStrings;

这将使用NULL值替换无效的日期和时间戳字符串。

答案 1 :(得分:0)

Load API没有足够的控件来控制无效DATE / TIMESTAMP值的行为 - 您可以在此处向BigQuery问题跟踪器提交功能请求:https://issuetracker.google.com/issues?q=componentid:187149。 与此同时,解决方法是按https://cloud.google.com/bigquery/external-data-sources#table_definitions_based_on_csv_source_files中所述使用CSV上的联合查询,并按照Elliott的回答中所述使用SAFE_CAST函数。