superset icon indicating copy to clipboard operation
superset copied to clipboard

SQL Server : Various issues

Open kedare opened this issue 9 years ago • 20 comments

Superset version

Superset 0.15.4 Centos 7 Python 3.6.0

alembic==0.8.10
amqp==1.4.9
anyjson==0.3.3
Babel==2.3.4
billiard==3.3.0.23
celery==3.1.23
cffi==1.9.1
click==6.7
colorama==0.3.7
crc16==0.1.1
cryptography==1.5.3
defusedxml==0.5.0
Flask==0.12
Flask-AppBuilder==1.8.1
Flask-Babel==0.11.1
Flask-Cache==0.13.1
Flask-Login==0.2.11
Flask-Migrate==1.5.1
Flask-OpenID==1.2.5
Flask-Script==2.0.5
Flask-SQLAlchemy==2.0
Flask-Testing==0.5.0
Flask-WTF==0.14.2
future==0.16.0
gunicorn==19.6.0
humanize==0.5.1
idna==2.2
itsdangerous==0.24
Jinja2==2.9.5
kombu==3.0.37
Mako==1.0.6
Markdown==2.6.6
MarkupSafe==0.23
mysqlclient==1.3.10
numpy==1.12.0
pandas==0.18.1
parsedatetime==2.0
ply==3.10
pyasn1==0.2.3
pycparser==2.17
pydruid==0.3.1
PyHive==0.2.1
pymssql==2.1.3
pyodbc==4.0.13
python-dateutil==2.5.3
python-editor==1.0.3
python-redis==0.1.4
python3-openid==3.1.0
pytz==2016.10
redis==2.10.5
requests==2.10.0
sasl==0.2.1
simplejson==3.8.2
six==1.10.0
SQLAlchemy==1.0.13
SQLAlchemy-Utils==0.32.7
sqlparse==0.1.19
superset==0.15.4
thrift==0.10.0
thrift-sasl==0.2.1
thriftpy==0.3.9
Werkzeug==0.11.10
WTForms==2.1

Expected results

When adding a SQL Server data source, I should see the list of tables. When adding a table, it should work

Actual results

When adding a SQL Server, the server is added successfully and the connection shown as OK, but the tables are not listed at the bottom of the form.

When adding a table manually, Superset complains that Table [dbo.Domain] could not be found, please double check your database connection, schema, and table name

Steps to reproduce

  1. Setup a connection using pymssql and freetds to a database
  2. Configure Superset to connect to it

####################

I'm trying to setup a SQL Server 2016 database with SuperSet and I'm having some issues :

I could check the debug logs of FreeTDS, for the first issue (Tables not showing when adding the database), I could see that the query FreeTDS run to discover the tables using targetting the "guest" schema, I have no idea why, I tried to find where was this guest thing configured, without success :

SELECT [TABLES_1].[TABLE_NAME]
FROM [INFORMATION_SCHEMA].[TABLES] AS [TABLES_1]
WHERE [TABLES_1].[TABLE_SCHEMA] = CAST(N'guest' AS NVARCHAR(max)) AND [TABLES_1].[TABLE_TYPE] = N'BASE TABLE' ORDER BY [TABLES_1].[TABLE_NAME]

Its returns nothing as guest doesn't exists.

For the second issue, when setting the schema and the correct table name, I can see on the query that it find the tables without issues and get the fields, but I don't know why SuperSet complains that it cannot find it, here is the query it runs :

SELECT [COLUMNS_1].[TABLE_SCHEMA], [COLUMNS_1].[TABLE_NAME], [COLUMNS_1].[COLUMN_NAME], [COLUMNS_1].[IS_NULLABLE], [COLUMNS_1].[DATA_TYPE], [COLUMNS_1].[ORDINAL_POSITION], [COLUMNS_1].[CHARACTER_MAXIMUM_LENGTH], [COLUMNS_1].[NUMERIC_PRECISION], [COLUMNS_1].[NUMERIC_SCALE], [COLUMNS_1].[COLUMN_DEFAULT], [COLUMNS_1].[COLLATION_NAME]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1]
WHERE [COLUMNS_1].[TABLE_NAME] = CAST(N'Domain' AS NVARCHAR(max)) AND [COLUMNS_1].[TABLE_SCHEMA] = CAST(N'dbo' AS NVARCHAR(max)) ORDER BY [COLUMNS_1].[ORDINAL_POSITION]

It returns the correct result, but SuperSet complains that it doesn't exists

Here is the "standard" FreeTDS I have :

[MyServer1]
	host = 10.0.0.xx
	port = 1433
	tds version = 8.0

Thank you.

kedare avatar Feb 27 '17 12:02 kedare

Also, on the SQL Editor, I can see all my schemas, but I can't see any tables in the schemas, only some internal view/tables like spt_monitor.

kedare avatar Feb 27 '17 14:02 kedare

I found one way to fix this. Apparently, the sqlalchemy only connect to the database that is defined as "Default database" on the user at SQL Server level.

Is there any other way to use a single user to connect to multiple databases ?

kedare avatar Feb 27 '17 16:02 kedare

@kedare this seems very related to similar issues observed on Postgres/Redshift as these databases have an extra layer of namespacing. Postgres has multiple schemas per "database" and SQL Server has multiple "owners" I believe.

SQLAlchemy, as a common denominator API to interface with these databases has some limitations and doesn't offer the abstractions we need to deal with all this (afaik).

It seems like ideally we'd need the left panel navigator in SQL Lab to allow to navigate the full namespacing of each database engine, with the proper labels for the dropdowns. For this to work, we'd have to customize the code a bit. Luckily there's already a placeholder module to handle this abstraction (db_engine_specs.py).

We need a comprehensive solution that will make it clear what the levels of namespacing are and related methods/endpoints to get lists of these objects.

mistercrunch avatar Feb 27 '17 17:02 mistercrunch

Airbnb won't drive this at this moment, only enable people in the community to do so. Whatever solution gets put in place we should make sure that it works for all db engines.

mistercrunch avatar Feb 27 '17 17:02 mistercrunch

What would be the best way to use it for a single schema ?

I could add the database, see the tables, but I can't run any query, I always get : (pymssql.OperationalError) (18456, b'DB-Lib error message 20018, severity 11:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (DBLive1:1433)\n')

And when checking SQL Server logs : Login failed for user 'app-superset'. Reason: Failed to open the explicitly specified database 'dbo'. [CLIENT: 10.0.0.xx]

It's trying to connect to the dbo database (That doesn't exists) instead of using the dbo schema. (I removed any explicit schema of the configuration)

kedare avatar Feb 27 '17 17:02 kedare

Hmm... I tested more, when I empty the "schema" field on the SQL Lab, I don't get this error anymore, but then when the query finishes running, I get an "Unserializable object"

kedare avatar Feb 27 '17 17:02 kedare

Hmm some tables work fine, some others not, maybe there are some datatype that can cause that ? I'll do more testing

kedare avatar Feb 27 '17 17:02 kedare

Here's a hacky fix we just landed (not deployed) for postgres: https://github.com/airbnb/superset/pull/1789/files

You could try adding mssql where it says redshift and see if it allows you to move forward

mistercrunch avatar Feb 27 '17 17:02 mistercrunch

Thanks, I will take a look.

I have another issue related to MSSQL, I could do a SQL query that appears fine in the SQL Editior, I can see the result also :

select c.Name as country, count(*) as count from House as h
inner join Country as c on h.country_id = c.id
group by c.Name
order by count desc

But when I try to graph it (with Vizualize, with the default parameter), if I try to get a Pie Chart for example (Count of each group), I get an "error" (Just the red div) with just " 'country' " inside.

I did something similar with a MySQL datasource without any issue.

Do you have any idea of what could be the cause ?

kedare avatar Feb 28 '17 08:02 kedare

I wouldn't alias using a reserved work (count). Could that be the issue?

mistercrunch avatar Feb 28 '17 16:02 mistercrunch

At the end I upgraded to Git head, and I could get the generated query. The issue was that as it's put as a subquery, you can't use a "ORDER BY". But should not it return the SQL error directly instead of this ?

kedare avatar Mar 01 '17 08:03 kedare

@kedare do you mind trying to add a line that says limit_method = LimitMethod.FETCH_MANY https://github.com/airbnb/superset/blob/master/superset/db_engine_specs.py#L337

The idea is that we want to limit the number of rows returned even when users query large tables. This line will change the approach from wrapping the user's SQL as a subquery to using the cursor's fetchmany(LIMIT) method instead.

Let me know if it works and please send that in a PR if it does.

mistercrunch avatar Mar 01 '17 23:03 mistercrunch

What test should I do to make sure it works ?

kedare avatar Mar 02 '17 09:03 kedare

Just making sure everything works including the issue you described earlier

mistercrunch avatar Mar 04 '17 04:03 mistercrunch

I have similar issue with superset 0.17.1 Python 2.7 Debian OperationalError: (pymssql.OperationalError) (18456, "Login failed for user 'SuperSet'.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (213.123.32.43:1433)\n") it occures when I'm trying run select from chosen table. I see this error in a server concole, but there is nothing in Superset Web UI.

denmak avatar Mar 20 '17 22:03 denmak

The same with 0.15.4

denmak avatar Mar 28 '17 23:03 denmak

(pymssql.OperationalError) (18456, 'DB-Lib error message 20018, severity 11:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (xxx.xxx.xxx.xxx:1433)\n')

denmak avatar Mar 28 '17 23:03 denmak

@kedare did you finaly resolve this MS SQL issue some how?

denmak avatar Mar 28 '17 23:03 denmak

I didn't had the time to check, I'll do it in the next days

kedare avatar Apr 01 '17 17:04 kedare

Notice: this issue has been closed because it has been inactive for 386 days. Feel free to comment and request for this issue to be reopened.

mistercrunch avatar Apr 23 '18 15:04 mistercrunch