Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot mount Snowflake as a data source behind a proxy #413

Closed
mapshen opened this issue Mar 25, 2021 · 19 comments · Fixed by #414 or #418
Closed

Cannot mount Snowflake as a data source behind a proxy #413

mapshen opened this issue Mar 25, 2021 · 19 comments · Fixed by #414 or #418

Comments

@mapshen
Copy link

mapshen commented Mar 25, 2021

We are evaluating splitgraph in our corporate env, where we have to go through a proxy to reach Snowflake.

When we do

sgr --version
sgr, version 0.2.10
sgr -v DEBUG mount snowflake test_snowflake -o@- <<EOF
heredoc> {
heredoc>     "username": "XXX",
heredoc>     "password": "XXX",
heredoc>     "account": "XXX",
heredoc>     "database": "XXX",
heredoc>     "schema": "XXX"
heredoc> }
heredoc> EOF

we get the following error

error: Traceback (most recent call last):
error:   File "/home/XXX/python3.7/site-packages/splitgraph/commandline/__init__.py", line 116, in invoke
error:     result = super(click.Group, self).invoke(ctx)
error:   File "/home/XXX/python3.7/site-packages/click/core.py", line 1259, in invoke
error:     return _process_result(sub_ctx.command.invoke(sub_ctx))
error:   File "/home/XXX/python3.7/site-packages/click/core.py", line 1259, in invoke
error:     return _process_result(sub_ctx.command.invoke(sub_ctx))
error:   File "/home/XXX/python3.7/site-packages/click/core.py", line 1066, in invoke
error:     return ctx.invoke(self.callback, **ctx.params)
error:   File "/home/XXX/python3.7/site-packages/click/core.py", line 610, in invoke
error:     return callback(*args, **kwargs)
error:   File "/home/XXX/python3.7/site-packages/splitgraph/commandline/mount.py", line 69, in _callback
error:     mount(schema, mount_handler=handler_name, handler_kwargs=handler_options)
error:   File "/home/XXX/python3.7/site-packages/splitgraph/hooks/mount_handlers.py", line 69, in mount
error:     source.mount(schema=mountpoint, overwrite=overwrite, tables=tables)
error:   File "/home/XXX/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 134, in mount
error:     self._create_foreign_tables(schema, server_id, tables)
error:   File "/home/XXX/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 144, in _create_foreign_tables
error:     _import_foreign_schema(self.engine, schema, remote_schema, server_id, tables)
error:   File "/home/XXX/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 299, in _import_foreign_schema
error:     engine.run_sql(query)
error:   File "/home/XXX/python3.7/site-packages/splitgraph/engine/postgres/engine.py", line 501, in run_sql
error:     cur.execute(statement, _convert_vals(arguments) if arguments else None)
error: psycopg2.errors.InternalError_: Error in python: OperationalError
error: DETAIL:  (snowflake.connector.errors.OperationalError) 250003: Failed to execute request: HTTPSConnectionPool(host='XXX.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=XXX&databaseName=XXX&schemaName=XXX&request_guid=XXX(Caused by ConnectTimeoutError(<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x7f31c8e0df98>, 'Connection to XXX.snowflakecomputing.com timed out. (connect timeout=60)'))
error: (Background on this error at: http://sqlalche.me/e/14/e3q8)

It seems although the snowflake connector Splitgraph uses supports proxy settings via HTTPS_PROXY, HTTP_PROXY and NO_PROXY [1], but it psycopg2 doesn't pass them over while creating new servers [2]?

[1] https://github.com/splitgraph/snowflake-sqlalchemy#using-a-proxy-server
[2] https://github.com/splitgraph/splitgraph/blob/3cc20ef9021c153344cb0e52247dcc9162812d50/splitgraph/hooks/data_source/fdw.py#L259

@mildbyte
Copy link
Contributor

Thanks for noticing this! I added a parameter to the data source that can be used to inject arbitrary envvars on the engine side when running the query. Testing (don't have a proxy handy but can verify it fails to connect, though it does take some time to fail, could be some retry logic in snowflake-connector-python):

$ sgr mount snowflake test_snowflake -o@- <<EOF
{
    "username": "uname",
    "password": "pass"
    "account": "acc",
    "database": "SNOWFLAKE_SAMPLE_DATA",
    "schema": "TPCH_SF100",
    "envvars": {"HTTPS_PROXY": "https://127.0.0.1"}
}
EOF
error: psycopg2.errors.InternalError_: Error in python: OperationalError
error: DETAIL:  (snowflake.connector.errors.OperationalError) 250003: 250003: Failed to execute request: HTTPSConnectionPool(host='wp71792.west-europe.azure.snowflakecomputing.com', port=443): Max retries exceeded with url: /session/v1/login-request?request_id=019f2a01-f306-4446-b224-ab28481ab1b6&databaseName=SNOWFLAKE_SAMPLE_DATA&schemaName=TPCH_SF100&request_guid=0e7a9b9a-2aae-4648-919f-4e2f40f1d6f7 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<snowflake.connector.vendored.urllib3.connection.HTTPSConnection object at 0x7f8394940f28>: Failed to establish a new connection: [Errno 111] Connection refused')))
error: (Background on this error at: http://sqlalche.me/e/14/e3q8)

@mapshen
Copy link
Author

mapshen commented Mar 25, 2021

@mildbyte thanks for the quick response. Much appreciated.

Looking at the errors, I realized I am running sgr on my localhost but the connection to snowflake is issued from my splitgraph engine, which is running inside a container that doesn't have proxy settings configured because I created it with sgr engine add.

So I worked around this by starting up our split engine with HTTPS_PROXY, HTTP_PROXY and NO_PROXY passed in

docker run -d \
    -e POSTGRES_PASSWORD=supersecure \
    -e POSTGRES_USER=sgr \
    -e POSTGRES_DB=splitgraph \
    -e SG_CONFIG_FILE=/.sgconfig \
    -e HTTPS_PROXY=http://proxy-host:9400 \
    -e HTTP_PROXY=http://proxy-host:9400 \
    -e NO_PROXY=localhost \
    -p 5432:5432 \
    -v $PWD/splitgraph_data:/var/lib/splitgraph/objects \
    -v $PWD/splitgraph_metadata:/var/lib/postgresql/data \
    -v $PWD/.splitgraph/.sgconfig:/.sgconfig \
    --name splitgraph_engine_default \
    splitgraph/engine:0.2.10

Back to this issue, would allowing sgr engine add to accept env vars a better solution?

@mildbyte
Copy link
Contributor

It's also an option. The difference is, on splitgraph.com/Splitgraph Cloud we manage these engines separately from connectors (e.g. one engine might end up handling several queries, powered by different connectors), so we can't set the envvars there globally, since we might not know them at the engine startup and we don't want to change them in the context of the whole engine.

@mapshen
Copy link
Author

mapshen commented Mar 26, 2021

That makes sense.

On a side note, would we consider supporting key pair auth [1]? Password auth is frowned upon inside the firm.

[1] https://github.com/splitgraph/snowflake-sqlalchemy#key-pair-authentication-support

@mildbyte
Copy link
Contributor

@mapshen It's definitely possible. We could pass this arg to the adapter:

    connect_args={
        'private_key': pkb,
        },
    )

which would also mean other SQLAlchemy adapters would be able to use connect_args (though we normally use another route for data sources to pass credentials: on the command line they're merged together, but in the cloud they're stored in a separate storage and treated as a secret: https://github.com/splitgraph/splitgraph/blob/master/splitgraph/ingestion/snowflake/__init__.py#L9-L20).

The only issue in this case is that you'd need to pass your passwordless private key as a connection param on the command line, rather than point sgr mount to it.

@mildbyte mildbyte reopened this Mar 26, 2021
@mildbyte
Copy link
Contributor

(PR autoclosed; will keep open for the private_key functionality)

@mapshen
Copy link
Author

mapshen commented Mar 27, 2021

The only issue in this case is that you'd need to pass your passwordless private key as a connection param on the command line, rather than point sgr mount to it.

There seems no better way based on the current design. Nevertheless, we don't have to send the key over the public internet as we do with the password.

@mildbyte
Copy link
Contributor

@mapshen Privkey support is now available:

sgr mount snowflake test_snowflake -o@- <<EOF
{
    "username": "uname",
    "private_key": "MIIEvQIBADANBgkq...",      <-- can also use the standard ===== BEGIN PRIVATE KEY ===== ... format
    "account": "acc",
    "database": "SNOWFLAKE_SAMPLE_DATA",
    "schema": "TPCH_SF100"
}
EOF

mildbyte added a commit that referenced this issue Mar 29, 2021
  * Snowflake data source improvements:
    * Allow passing envvars to set HTTP proxy parameters, fix incorrect query string generation when passing a warehouse (#414, #413)
    * Support for authentication using a private key (#418)
  * Splitfiles: relax AST restrictions to support all SELECT/INSERT/UPDATE/DELETE statements (#411)
  * Change the default installation port to 6432 and handle port conflicts during install (#375)
  * Add retry logic to fix registry closing the SSL connection after 30 seconds, close remote connections in some places (#417)
@mapshen
Copy link
Author

mapshen commented Mar 30, 2021

@mildbyte not sure if this is a regression caused by ef427f6, but when I run

sgr -v DEBUG mount snowflake test_snowflake -o@- <<EOF
heredoc> {
heredoc>     "username": "XXX",
heredoc>     "password": "XXX",
heredoc>     "account": "XXX",
heredoc>     "database": "XXX",
heredoc>     "schema": "XXX"
heredoc> }
heredoc> EOF

in 0.2.11, i get the following error:

error: Traceback (most recent call last):
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/commandline/__init__.py", line 116, in invoke
error:     result = super(click.Group, self).invoke(ctx)
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
error:     return _process_result(sub_ctx.command.invoke(sub_ctx))
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
error:     return _process_result(sub_ctx.command.invoke(sub_ctx))
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
error:     return ctx.invoke(self.callback, **ctx.params)
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 610, in invoke
error:     return callback(*args, **kwargs)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/commandline/mount.py", line 69, in _callback
error:     mount(schema, mount_handler=handler_name, handler_kwargs=handler_options)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/mount_handlers.py", line 69, in mount
error:     source.mount(schema=mountpoint, overwrite=overwrite, tables=tables)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 134, in mount
error:     self._create_foreign_tables(schema, server_id, tables)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 144, in _create_foreign_tables
error:     _import_foreign_schema(self.engine, schema, remote_schema, server_id, tables)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 299, in _import_foreign_schema
error:     engine.run_sql(query)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/engine/postgres/engine.py", line 507, in run_sql
error:     cur.execute(statement, _convert_vals(arguments) if arguments else None)
error: psycopg2.errors.InternalError_: Error in python: TypeError
error: DETAIL:  'NoneType' object is not iterable
error: 

@mildbyte
Copy link
Contributor

@mapshen Can you send me the output of sgr engine log (or the logs of the splitgraph_engine_default Docker container)? There should be a stack trace at the end of it.

@mildbyte
Copy link
Contributor

Nevermind, just managed to reproduce. Fix incoming.

@mapshen
Copy link
Author

mapshen commented Mar 30, 2021

FWIW, here it is:

2021-03-30 19:13:38.419 GMT [119] STATEMENT:  IMPORT FOREIGN SCHEMA "TPCH_SF100" FROM SERVER "snowflake_sample_data_multicorn_server" INTO "snowflake_sample_data"
2021-03-30 19:14:10,655 [162] INFO Failed to import optional packages, pyarrow
2021-03-30 19:14:10.664 GMT [162] ERROR:  Error in python: TypeError
2021-03-30 19:14:10.664 GMT [162] DETAIL:  Traceback (most recent call last):

          File "/usr/local/lib/python3.7/dist-packages/multicorn-1.4.0.dev0-py3.7-linux-x86_64.egg/multicorn/sqlalchemyfdw.py", line 598, in import_schema
            url, schema, restriction_type, restricts, connect_args

          File "/usr/local/lib/python3.7/dist-packages/multicorn-1.4.0.dev0-py3.7-linux-x86_64.egg/multicorn/sqlalchemyfdw.py", line 606, in _import_schema
            engine = create_engine(url, connect_args=connect_args)

          File "<string>", line 2, in create_engine

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/deprecations.py", line 298, in warned
            return fn(*args, **kwargs)

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/create.py", line 565, in create_engine
            cparams.update(pop_kwarg("connect_args", {}))

        TypeError: 'NoneType' object is not iterable

@mildbyte
Copy link
Contributor

Should be fixed now (#421) -- the reason was that sqlalchemy didn't like us passing an empty connect_args when there was no private key.

You shouldn't need to upgrade splitgraph itself, but you'll need to use a version of the engine I pushed out until we cut a proper release:

sgr engine upgrade --image splitgraph/engine:0.2.11-snowflake-hotfix

(you can also build it yourself with

git clone https://github.com/splitgraph/splitgraph.git
cd splitgraph
git checkout --recurse-submodules 2355d9776921b66798072ea6550adeeea11737d8
cd engine
make build   # with_postgis=1 if you need PostGIS
sgr engine upgrade --image splitgraph/engine:development --no-pull

)

@mapshen
Copy link
Author

mapshen commented Mar 31, 2021

Thanks for the quick turnaround! I spun up another engine with splitgraph/engine:0.2.11-snowflake-hotfix and when do

sgr -v DEBUG mount snowflake test_snowflake -o@- <<EOF
heredoc> {
heredoc>     "username": "XXX",
heredoc>     "password": "XXX",
heredoc>     "account": "XXX",
heredoc>     "database": "XXX",
heredoc>     "schema": "XXX"
heredoc> }
heredoc> EOF

now the error becomes:

error: Traceback (most recent call last):
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/commandline/__init__.py", line 116, in invoke
error:     result = super(click.Group, self).invoke(ctx)
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
error:     return _process_result(sub_ctx.command.invoke(sub_ctx))
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
error:     return _process_result(sub_ctx.command.invoke(sub_ctx))
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
error:     return ctx.invoke(self.callback, **ctx.params)
error:   File "/XXX/lib/python3.7/site-packages/click/core.py", line 610, in invoke
error:     return callback(*args, **kwargs)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/commandline/mount.py", line 69, in _callback
error:     mount(schema, mount_handler=handler_name, handler_kwargs=handler_options)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/mount_handlers.py", line 69, in mount
error:     source.mount(schema=mountpoint, overwrite=overwrite, tables=tables)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 134, in mount
error:     self._create_foreign_tables(schema, server_id, tables)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 144, in _create_foreign_tables
error:     _import_foreign_schema(self.engine, schema, remote_schema, server_id, tables)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/hooks/data_source/fdw.py", line 299, in _import_foreign_schema
error:     engine.run_sql(query)
error:   File "/XXX/lib/python3.7/site-packages/splitgraph/engine/postgres/engine.py", line 507, in run_sql
error:     cur.execute(statement, _convert_vals(arguments) if arguments else None)
error: psycopg2.errors.InternalError_: Error in python: ProgrammingError
error: DETAIL:  (snowflake.connector.errors.ProgrammingError) 002043 (02000): 019b46f0-05c0-8f52-0000-4fbd09871ada: SQL compilation error:
error: Object does not exist, or operation cannot be performed.
error: [SQL: SHOW /* sqlalchemy:get_table_names */ TABLES IN SNOWFLAKE_SAMPLE_DATA]
error: (Background on this error at: http://sqlalche.me/e/14/f405)

On the engine side it is:

2021-03-31 16:21:21,713 [1732] INFO Failed to import optional packages, pyarrow
2021-03-31 16:21:21,723 [1732] INFO Snowflake Connector for Python Version: 2.4.1, Python Version: 3.7.3, Platform: Linux-3.10.0-1062.el7.x86_64-x86_64-with-debian-10.4
2021-03-31 16:21:21,723 [1732] INFO This connection is in OCSP Fail Open Mode. TLS Certificates would be checked for validity and revocation status. Any other Certificate Revocation related exceptions or OCSP Responder failures would be disregarded in favor of connectivity.
2021-03-31 16:21:21,723 [1732] INFO Setting use_openssl_only mode to False
2021-03-31 16:21:22,770 [1732] INFO query: [ROLLBACK]
2021-03-31 16:21:22,977 [1732] INFO query execution done
2021-03-31 16:21:22,978 [1732] INFO query: [ROLLBACK]
2021-03-31 16:21:23,170 [1732] INFO query execution done
2021-03-31 16:21:23,174 [1732] INFO query: [SHOW /* sqlalchemy:get_table_names */ TABLES IN "SNOWFLAKE_SAMPLE_DATA"]
2021-03-31 16:21:23,426 [1732] INFO query execution done
2021-03-31 16:21:23,439 [1732] INFO query: [ROLLBACK]
2021-03-31 16:21:23,656 [1732] INFO query execution done
2021-03-31 16:21:23,657 [1732] INFO query: [ROLLBACK]
2021-03-31 16:21:23,859 [1732] INFO query execution done
2021-03-31 16:21:23.862 GMT [1732] ERROR:  Error in python: ProgrammingError
2021-03-31 16:21:23.862 GMT [1732] DETAIL:  Traceback (most recent call last):

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1706, in _execute_context
            cursor, statement, parameters, context

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/default.py", line 681, in do_execute
            cursor.execute(statement, parameters)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/connector/cursor.py", line 628, in execute
            errvalue)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/connector/errors.py", line 236, in errorhandler_wrapper
            cursor.errorhandler(connection, cursor, error_class, error_value)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/connector/errors.py", line 176, in default_errorhandler
            cursor=cursor

        snowflake.connector.errors.ProgrammingError: 002043 (02000): 019b46f5-0510-8201-0000-4fbd09872b96: SQL compilation error:
        Object does not exist, or operation cannot be performed.


        The above exception was the direct cause of the following exception:


        Traceback (most recent call last):

          File "/usr/local/lib/python3.7/dist-packages/multicorn-1.4.0.dev0-py3.7-linux-x86_64.egg/multicorn/sqlalchemyfdw.py", line 607, in import_schema
            url, schema, restriction_type, restricts, connect_args

          File "/usr/local/lib/python3.7/dist-packages/multicorn-1.4.0.dev0-py3.7-linux-x86_64.egg/multicorn/sqlalchemyfdw.py", line 624, in _import_schema
            metadata.reflect(bind=engine, schema=schema, views=True, only=only)

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/sql/schema.py", line 4670, in reflect
            available = util.OrderedSet(insp.get_table_names(schema))

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/reflection.py", line 267, in get_table_names
            conn, schema, info_cache=self.info_cache

          File "<string>", line 2, in get_table_names

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/reflection.py", line 55, in cache
            ret = fn(self, con, *args, **kw)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/sqlalchemy/snowdialect.py", line 505, in get_table_names
            self._denormalize_quote_join(schema))))

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1200, in execute
            return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/sql/elements.py", line 314, in _execute_on_connection
            self, multiparams, params, execution_options

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1399, in _execute_clauseelement
            cache_hit=cache_hit,

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1749, in _execute_context
            e, statement, parameters, cursor, context

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1930, in _handle_dbapi_exception
            sqlalchemy_exception, with_traceback=exc_info[2], from_=e

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/compat.py", line 198, in raise_
            raise exception

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/base.py", line 1706, in _execute_context
            cursor, statement, parameters, context

          File "/usr/local/lib/python3.7/dist-packages/sqlalchemy/engine/default.py", line 681, in do_execute
            cursor.execute(statement, parameters)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/connector/cursor.py", line 628, in execute
            errvalue)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/connector/errors.py", line 236, in errorhandler_wrapper
            cursor.errorhandler(connection, cursor, error_class, error_value)

          File "/usr/local/lib/python3.7/dist-packages/snowflake/connector/errors.py", line 176, in default_errorhandler
            cursor=cursor

        sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 002043 (02000): 019b46f5-0510-8201-0000-4fbd09872b96: SQL compilation error:
        Object does not exist, or operation cannot be performed.
        [SQL: SHOW /* sqlalchemy:get_table_names */ TABLES IN "SNOWFLAKE_SAMPLE_DATA"]
        (Background on this error at: http://sqlalche.me/e/14/f405)

Would mind taking a further look? It seems something is wrong with sqlalchemy:get_table_names. It works if I do

$ sgr mount snowflake test_snowflake_subquery -o@- <<EOF
{
    "username": "username",
    "password": "password",
    "account": "acc-id.west-europe.azure",
    "database": "SNOWFLAKE_SAMPLE_DATA",
    "tables": {
        "balances": {
            "schema": {
                "n_nation": "varchar",
                "segment": "varchar",
                "avg_balance": "numeric"
            }
            "options": {
                "subquery": "SELECT n_nation AS nation, c_mktsegment AS segment, AVG(c_acctbal) AS avg_balance FROM TPCH_SF100.customer c JOIN TPCH_SF100.nation n ON c_nationkey = n_nationkey"
            }
        }
    }
}
EOF

but doesn't if I leave out tables or supply it as a list of tables like ["NATION", "PART"].

@mildbyte
Copy link
Contributor

It might be a limitation of sqlalchemy + snowflake itself where you have to pass in a schema name (e.g. "schema": "TPCH_SF100" like in #413 (comment)), otherwise it won't be able to do introspection since there's no default schema set?

@mapshen
Copy link
Author

mapshen commented Mar 31, 2021

I do have a schema specified and you can see from the above errors that SNOWFLAKE_SAMPLE_DATA is the schema name:

error: psycopg2.errors.InternalError_: Error in python: ProgrammingError
error: DETAIL:  (snowflake.connector.errors.ProgrammingError) 002043 (02000): 019b46f0-05c0-8f52-0000-4fbd09871ada: SQL compilation error:
error: Object does not exist, or operation cannot be performed.
error: [SQL: SHOW /* sqlalchemy:get_table_names */ TABLES IN SNOWFLAKE_SAMPLE_DATA]
error: (Background on this error at: http://sqlalche.me/e/14/f405)

@mildbyte
Copy link
Contributor

snowflake_sample_data is the db name in this context. I don't think it can actually list all tables and all schemas (you can only sgr mount one schema at a time, unless you're using subqueries, where you can reference any schemata)

@mildbyte
Copy link
Contributor

mildbyte commented Mar 31, 2021

Ah! You want to flip these (database and schema):

sgr -v DEBUG mount snowflake snowflake_sample_data -o@- <<EOF
heredoc> {
heredoc>     "username": "XXX",
heredoc>     "password": "XXX",
heredoc>     "account": "XXX",
heredoc>     "database": "SNOWFLAKE_SAMPLE_DATA",
heredoc>     "schema": "TPCH_SF100"
heredoc> }
heredoc> EOF

@mapshen
Copy link
Author

mapshen commented Mar 31, 2021

You're right! Thanks for pointing this out. I've got the db and schema misplaced. Should've had my today's coffee before posting this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants