aaronsteers
11/02/2022, 4:39 PMaaronsteers
11/02/2022, 4:40 PMHenning Holgersen
11/02/2022, 5:44 PMsinger_sdk/connectors/sql.py
file, I see that the comparison in the merge and in the adapt_column_type methods are a little different, but it looks like they both render the collation as part of the type comparison.
Column types are returned from the database, and explicitly cast by the sdk into a sqlalchemy.types.TypeEngine
type. This is then compared to a sqlalchemy.types.TypeEngine
that has been created by the to_sql_type
method from a json-schema definition (i.e. never touched the database).
The comparison is in the form of if str(sql_type) == str(current_type):
, and the str
function prints not just VARCHAR() but also the collation, as a string, so it doesn’t match. That is in the adapt_column_type method. somewhat different in the merge method.
Two ways to solve this:
Generic in case other databases have similar issues when the dialect prints something more:
use some method other than str
for comparison. Sqlalchemy has some abstract comparator method but that might not be the way to go, idk, we might have to create our own little column comparator method.
Specific for mssql, we could make sure the varchar/nvarchar types generated from the singer schema is given the correct collation, which is for most cases should be easy enough to do by checking the collation in the database.
As of yet, I don’t know why this isn’t a problem for Derek’s mssql target.aaronsteers
11/02/2022, 6:47 PMaaronsteers
11/02/2022, 6:49 PMHenning Holgersen
11/02/2022, 6:52 PMvisch
11/02/2022, 6:54 PMvisch
11/02/2022, 6:54 PMBuzzCutNorman
11/02/2022, 7:28 PM/*********************************
Create the simple test table
in an MSSQL database
*********************************/
CREATE TABLE SampleData.dbo.testme (
Id int IDENTITY(1,1) PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
go
/*********************************
Insert some test data into the
test table
*********************************/
INSERT INTO [SampleData].[dbo].[testme]
([LastName]
,[FirstName]
,[Age])
VALUES
('Norman','BuzzCut',20)
,('Duck','Donald',90)
,('Mouse','Mickey',100)
go
/********************************
Create another database as a target
in MSSQL and test meltano run,
then truncate and run again
********************************/
truncate table datawarehouse.dbo.testme
/******************************
Truncate the target table again
then run this and you will get the
error if you do a meltano run
*******************************/
ALTER TABLE datawarehouse.dbo.testme
ALTER COLUMN LastName VARCHAR(255) COLLATE Latin1_General_100_CI_AI_SC;
christoph
11/02/2022, 10:01 PMvarchar()
and not nvarchar()
?BuzzCutNorman
11/02/2022, 10:05 PMHenning Holgersen
11/02/2022, 10:08 PMBuzzCutNorman
11/02/2022, 10:13 PMnvarchar()
and varchar()
you end up with the same error.BuzzCutNorman
11/02/2022, 10:16 PMchristoph
11/02/2022, 10:43 PMvisch
11/03/2022, 1:56 PMvisch
11/03/2022, 1:56 PMchristoph
11/03/2022, 8:01 PMchristoph
11/03/2022, 8:06 PMBuzzCutNorman
11/03/2022, 11:20 PM