mirror of
https://github.com/sqlfluff/sqlfluff
synced 2025-12-17 19:31:32 +00:00
BigQuery: explicitly define data types (#7305)
Co-authored-by: Annebelle Olminkhof <20630578+annebelleo@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6a49fdd4fc
commit
e683a71d58
@@ -290,6 +290,40 @@ bigquery_dialect.replace(
|
||||
casefold=str.upper,
|
||||
)
|
||||
),
|
||||
DatatypeIdentifierSegment=SegmentGenerator(
|
||||
lambda dialect: MultiStringParser(
|
||||
[
|
||||
"INT64",
|
||||
"INT",
|
||||
"SMALLINT",
|
||||
"INTEGER",
|
||||
"BIGINT",
|
||||
"TINYINT",
|
||||
"BYTEINT",
|
||||
"FLOAT64",
|
||||
"NUMERIC",
|
||||
"DECIMAL",
|
||||
"BIGNUMERIC",
|
||||
"BIGDECIMAL",
|
||||
"BOOL",
|
||||
"BOOLEAN",
|
||||
"STRING",
|
||||
"BYTES",
|
||||
"DATE",
|
||||
"DATETIME",
|
||||
"TIME",
|
||||
"TIMESTAMP",
|
||||
"GEOGRAPHY",
|
||||
"INTERVAL",
|
||||
"JSON",
|
||||
"RANGE",
|
||||
"ARRAY",
|
||||
"STRUCT",
|
||||
],
|
||||
CodeSegment,
|
||||
type="data_type_identifier",
|
||||
)
|
||||
),
|
||||
FunctionContentsExpressionGrammar=OneOf(
|
||||
Ref("DatetimeUnitSegment"),
|
||||
Ref("DatePartWeekSegment"),
|
||||
|
||||
@@ -4,7 +4,7 @@ import hypothesis.strategies as st
|
||||
import pytest
|
||||
from hypothesis import example, given, note, settings
|
||||
|
||||
from sqlfluff.core import FluffConfig
|
||||
from sqlfluff.core import FluffConfig, Linter
|
||||
from sqlfluff.core.parser import Lexer, Parser
|
||||
|
||||
|
||||
@@ -90,3 +90,11 @@ def test_bigquery_table_reference_segment_iter_raw_references(
|
||||
orp.part for orp in table_reference.iter_raw_references()
|
||||
]
|
||||
assert reference_parts == actual_reference_parts
|
||||
|
||||
|
||||
def test_cast_as_float_fails():
|
||||
"""CAST(... AS FLOAT) should fail for BigQuery (only FLOAT64 allowed)."""
|
||||
sql = "SELECT CAST('4.0' AS FLOAT)"
|
||||
parsed = Linter(dialect="bigquery").parse_string(sql)
|
||||
# Parsing produces a parse error for the unsupported `FLOAT` type.
|
||||
assert parsed.violations
|
||||
|
||||
@@ -4,7 +4,7 @@ qs(
|
||||
foo2 ARRAY<STRING>,
|
||||
foo3 STRUCT<x INT64>,
|
||||
foo4 STRUCT<x INT64, y INT64>,
|
||||
foo5 STRUCT<a ARRAY<FLOAT>, b STRUCT<x INT64, y INT64>>
|
||||
foo5 STRUCT<a ARRAY<FLOAT64>, b STRUCT<x INT64, y INT64>>
|
||||
)
|
||||
RETURNS STRUCT<product_id ARRAY<INT64>>
|
||||
LANGUAGE js AS """
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# computed by SQLFluff when running the tests. Please run
|
||||
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
|
||||
# altering SQL files.
|
||||
_hash: d1fa0d72cc2af0530c5f21c4cea3da882175a110632f386d1752c6136a1bb15f
|
||||
_hash: 09fea1147a6721122baff61b940cabd21edd638edb25e3829479fea628e1b460
|
||||
file:
|
||||
statement:
|
||||
create_function_statement:
|
||||
@@ -66,7 +66,7 @@ file:
|
||||
keyword: ARRAY
|
||||
start_angle_bracket: <
|
||||
data_type:
|
||||
data_type_identifier: FLOAT
|
||||
data_type_identifier: FLOAT64
|
||||
end_angle_bracket: '>'
|
||||
- comma: ','
|
||||
- parameter: b
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# computed by SQLFluff when running the tests. Please run
|
||||
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
|
||||
# altering SQL files.
|
||||
_hash: b3eb84334d4a93f639f727dd59f0833c1332eab98414140b0076dae106703690
|
||||
_hash: bfa63bceb292ee595dc0f2d449ee416a35c43b97ae6289ac6d6844c8bfdd3d3b
|
||||
file:
|
||||
- statement:
|
||||
select_statement:
|
||||
@@ -87,8 +87,9 @@ file:
|
||||
- data_type:
|
||||
data_type_identifier: STRING
|
||||
- expression:
|
||||
data_type:
|
||||
data_type_identifier: FORMAT
|
||||
column_reference:
|
||||
naked_identifier: FORMAT
|
||||
- expression:
|
||||
quoted_literal: "'ASCII'"
|
||||
- end_bracket: )
|
||||
alias_expression:
|
||||
@@ -114,8 +115,9 @@ file:
|
||||
- data_type:
|
||||
data_type_identifier: STRING
|
||||
- expression:
|
||||
data_type:
|
||||
data_type_identifier: FORMAT
|
||||
column_reference:
|
||||
naked_identifier: FORMAT
|
||||
- expression:
|
||||
quoted_literal: "'YYYY-MM-DD HH24:MI:SS TZH:TZM'"
|
||||
- end_bracket: )
|
||||
alias_expression:
|
||||
|
||||
Reference in New Issue
Block a user