Skip to content

SNOW-638839: MERGE INTO does not render argument correctly #322

Closed as not planned
@luciengaitskell

Description

@luciengaitskell

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

    3.9.10

  2. What operating system and processor architecture are you using?

    Linux-5.10.0-16-cloud-amd64-x86_64-with-glibc2.31

  3. What are the component versions in the environment (pip freeze)?

    SQLAlchemy==1.4.31
    snowflake-connector-python==2.7.8
    snowflake-sqlalchemy==1.3.4
    
  4. What did you do?

from snowflake.sqlalchemy import MergeInto, dialect
from sqlalchemy import Column, Integer, MetaData, Table, select
from sqlalchemy.orm import aliased

meta = MetaData()

target_table = Table(
    "target_table",
    meta,
    Column("a", Integer),
)

source_table = aliased(
    Table(
        "some_table",
        meta,
        Column("a", Integer),
        Column("b", Integer),
    ),
    name="source_table",
)

# Example subquery if more processing needed ontop:
source = select(
    source_table.c["a"].label("a"),
    source_table.c["b"].label("b"),
).subquery("source")

op = MergeInto(target_table, source, target_table.c.a == source.c.a)

print(op.compile(dialect=dialect()))

Result:

MERGE INTO target_table USING SELECT source_table.a AS a, source_table.b AS b 
FROM some_table AS source_table ON target_table.a = source.a
  1. What did you expect to see?
MERGE INTO target_table USING (SELECT source_table.a AS a, source_table.b AS b 
FROM some_table AS source_table) AS source ON target_table.a = source.a

6. Can you set logging to DEBUG and collect the logs?

import logging
import os

for logger_name in ['snowflake.sqlalchemy', 'snowflake.connector']:
   logger = logging.getLogger(logger_name)
   logger.setLevel(logging.DEBUG)
   ch = logging.StreamHandler()
   ch.setLevel(logging.DEBUG)
   ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s'))
   logger.addHandler(ch)

The problem is already debugged and addrssed in #321

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions