Skip to content

Commit

Permalink
fix snowflake tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryTravis committed Aug 27, 2024
1 parent 8460c82 commit b8c9ca4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions test/Snowflake_Tests/src/Snowflake_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ snowflake_specific_spec suite_builder default_connection db_name setup =
col . cast Value_Type.Decimal . round 1 . value_type . should_equal (Value_Type.Decimal 38 0)

col . cast Value_Type.Float . round use_bankers=True . value_type . should_equal Value_Type.Float
col . cast Value_Type.Integer . round use_bankers=True . value_type . should_equal (Value_Type.Decimal 38 0)
col . cast Value_Type.Decimal . round use_bankers=True . value_type . should_equal (Value_Type.Decimal 38 0)
col . cast Value_Type.Integer . round use_bankers=True . value_type . should_equal (Value_Type.Decimal 38 6)
col . cast Value_Type.Decimal . round use_bankers=True . value_type . should_equal (Value_Type.Decimal 38 6)

col . cast Value_Type.Float . ceil . value_type . should_equal Value_Type.Float
col . cast Value_Type.Integer . ceil . value_type . should_equal (Value_Type.Decimal 38 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,25 @@ type Names_Data
type Lazy_Ref
Value ~get

type Connection_Data
Value ~data

connection self = self.data.at 0

setup create_connection_fn = Connection_Data.Value <|
connection = create_connection_fn Nothing
[connection]

teardown self =
self.connection.close

add_specs suite_builder setup =
prefix = setup.prefix
table_builder = setup.table_builder
create_connection_fn = setup.create_connection_func
light_table_builder = setup.light_table_builder
pending_datetime = if setup.test_selection.date_time.not then "Date/Time operations are not supported by this backend."

suite_builder.group prefix+"(Column_Operations_Spec) Rounding numeric tests" group_builder->
round_one n dp=0 use_bankers=False =
table = light_table_builder [["x", [n]]]
Expand Down Expand Up @@ -1749,27 +1763,33 @@ add_specs suite_builder setup =

if setup.is_database then
suite_builder.group prefix+"(Column_Operations_Spec) Column.let" group_builder->
group_builder.specify "Should allow the use of let-style CTEs" <|
t = table_builder [["X", [1, 2, 3, 4]], ["Y", [4, 3, 100, 200]], ["Z", [12.1, 23.4, -4.5, 44.33]]]
x = t.at "X"
y = t.at "Y"
z = t.at "Z"
a = ((x - 2.3) * (y + 1)) + z
b = (x - 2.3).let "xx" xx-> (xx * (y + 1)) + z
c = (x - 2.3).let "xx" xx-> (y + 1).let "yy" yy-> (xx * yy) + z
d = ((x - 2.3) * (y + 1)).let "xxyy" xxyy-> xxyy + z

r = a . rename "a" . to_table . set b "b" . set c "c" . set d "d" . read
r.at "a" . to_vector . should_equal [5.6000000000000005, 22.2, 66.20000000000002, 386.03000000000003]
r.at "a" . to_vector . should_equal (r.at "b" . to_vector)
r.at "a" . to_vector . should_equal (r.at "c" . to_vector)
r.at "a" . to_vector . should_equal (r.at "d" . to_vector)

a.to_table.to_sql . prepare . at 0 . should_not_contain "WITH"
b.to_table.to_sql . prepare . at 0 . should_contain 'xx_0'
c.to_table.to_sql . prepare . at 0 . should_contain 'xx_0'
c.to_table.to_sql . prepare . at 0 . should_contain 'yy_1'
d.to_table.to_sql . prepare . at 0 . should_contain 'xxyy_0'
connection_data = Connection_Data.setup create_connection_fn

group_builder.teardown <|
connection_data.teardown

if connection_data.connection.dialect.supports_nested_with_clause then
group_builder.specify "Should allow the use of let-style CTEs" <|
t = table_builder [["X", [1, 2, 3, 4]], ["Y", [4, 3, 100, 200]], ["Z", [12.1, 23.4, -4.5, 44.33]]]
x = t.at "X"
y = t.at "Y"
z = t.at "Z"
a = ((x - 2.3) * (y + 1)) + z
b = (x - 2.3).let "xx" xx-> (xx * (y + 1)) + z
c = (x - 2.3).let "xx" xx-> (y + 1).let "yy" yy-> (xx * yy) + z
d = ((x - 2.3) * (y + 1)).let "xxyy" xxyy-> xxyy + z

r = t . set a "a" . set b "b" . set c "c" . set d "d" . order_by ["X"] . read
r.at "a" . to_vector . should_equal [5.6000000000000005, 22.2, 66.20000000000002, 386.03000000000003]
r.at "a" . to_vector . should_equal (r.at "b" . to_vector)
r.at "a" . to_vector . should_equal (r.at "c" . to_vector)
r.at "a" . to_vector . should_equal (r.at "d" . to_vector)

a.to_table.to_sql . prepare . at 0 . should_not_contain "WITH"
b.to_table.to_sql . prepare . at 0 . should_contain 'xx_0'
c.to_table.to_sql . prepare . at 0 . should_contain 'xx_0'
c.to_table.to_sql . prepare . at 0 . should_contain 'yy_1'
d.to_table.to_sql . prepare . at 0 . should_contain 'xxyy_0'

suite_builder.group prefix+"(Column_Operations_Spec) Table.make_constant_column" group_builder->
group_builder.specify "Should allow the creation of constant columns" <|
Expand Down

0 comments on commit b8c9ca4

Please sign in to comment.