Hallo I have a problem I can’t solve with Extracto...
# troubleshooting
m
Hallo I have a problem I can’t solve with Extractor for MSSQL, tap-mssql --variant buzzcutnorman The MSSQL DB has a column name which is called index, which is of course a keyword. Error is pymssql._mssql.mssqldatabaseexception Incorrect syntax near ‘index’ . If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required ... My question is how can I edit this. I found that I could use stream maps (https://sdk.meltano.com/en/latest/stream_maps.html). Unfortunately it still doesn’t work for me because I guess I haven’t found the right syntax how I can use it. Could someone help me sort this out?
1
b
If possible could you please provided the stack trace of the error.
m
Unfortunately I can’t post here the stack trace of the error. But the parameters are so -> [parameters :({‘id’: 1, ‘index’: 0, ...<SOME_OTHER_PARAMETERS>})] Full Error message -> sqlalchemy.exc.OperationalError: (pymssql.exceptions.OperationalError) (1018, b”Incorrect syntax near ‘index’. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See See SQL Server Books Online for proper synatx.DB-Lib error message 20018, serverity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n”) I think the problem is because the index has single quotation. The T-SQL syntax should be [index] for that case.
b
No worries you have given me enough info to create a test scenario that will hopefully recreate the same error for me.
❤️ 1
m
What is even more interesting is that the table with columns is created but the error occurs only when the data is copied to a new destination.
b
That is great info to know thanks 🙏 for sharing that.
I will be able to look at this more 4 hours from now.
👍 1
I used the script below to create a test table with an column named
index
. The select I put in the meltano.yml looks like this
Copy code
select:
    - 'dbo-ColumnTrouble.*'
I did a
meltano install --clean
then set
driver_type: pymssql
ran
meltano select tap-mssql --list
to make sure the table was selected. Then ran
meltano invoke tap-mssql
and got all the rows without error. I also ran
meltano run tap-mssql target-postgres
and all the data wrote without error. Please give the following command a try
meltano install --clean
and then in your config only select the table with the
index
column and try
meltano invoke tap-mssql
and let me know what happens.
Copy code
use [testdata]
go
/*********************************
Create the simple test table
in an MSSQL database
*********************************/
DROP TABLE IF EXISTS [ColumnTrouble];
CREATE TABLE ColumnTrouble (
    Id int IDENTITY(1,1) PRIMARY KEY,
    Item varchar(255) NOT NULL,
    [index] int,
);
go
/*********************************
Insert some test data into the
test table
*********************************/
INSERT INTO [testdata].[dbo].[ColumnTrouble]
           ([Item]
           ,[index])
     VALUES
           ('Park Ticket', 100)
           ,('Churro', 200)
           ,('Lunch', 300)
           ,('Character Signature', 400)
;
go
/********************************
Query the new test tables
********************************/
select * from ColumnTrouble;
m
Thank you I will look at it on Monday because I don’t have access from home.
Hi, I tried selected the trouble table and run then
run meltano install --clean
,
meltano invoke tap-mssql
and this went without error but
meltano run
threw me the same error as before.
The column
index
is
bigint, null
in my case.
meltano invoke
output is:
{"type": "RECORD", "stream": "dbo-Redirect", "record" : {"Id": 1, "SourceUrl": "SOME_URL", "Index": 2097}, "time_extracted": "SOME_TIME"}
I think the problem is in the loader https://github.com/storebrand/target-mssql because the extractor work as expected.
b
Nice, you made good progress. You have worked through the basic troubleshooting and have a good understanding of the issue you are up against. A stream map for the
Index
stream property might be the quickest path to a resolution.
m
Please, could you also advise me how I could fix it because I have several Keywords as column name in different tables. I tried the
meltano-map-transform
as well but without success.
b
Michal, @Edgar Ramírez (Arch.dev) helped me understand how to properly configure a singer-sdk plugin with a stream map. The first trick is that the
stream_maps
needs to be in the
config:
. This definition crosswalk was helpful to me when looking at the source database and stream map config. • stream = table • property = column I found an example that showed how you can
__NULL__
or remove a stream's property but then match the property's value to a new property name. A config like this one should get you past the issue.
Copy code
plugins:
  extractors:
  - name: tap-mssql
    variant: buzzcutnorman
    pip_url: git+<https://github.com/BuzzCutNorman/tap-mssql.git>
    config:
      dialect: mssql
      driver_type: pymssql
      host: server 
      user: user
      database: database
      stream_maps:
        dbo-Redirect:
          Index: __NULL__
          ColumnIndex: index
    select:
    - 'dbo-Redirect.*'
When I get tap-mssql upgraded to SDK 0.37 you can do a more global fix I think. https://github.com/meltano/sdk/releases/tag/v0.37.0
👍 1
m
Thank you for the quick answer but it still doesn’t work. When I additionally cast the column to str(Index) there was another error: jsonschema.exceptions.ValidationError: ‘Index’ is a required property and Failed validating ‘required’ in schema.
stream_maps:
dbo-Redirect:
Index: __NULL__
index_field: str(Index)
I needed to cast it because without it I had a casting error
I tried other extractors but they didn’t work almost at all, they had a lot of other bugs.
@BuzzCutNorman I was thinking that I would modify the loader that would check the Schema and if it encountered a Keyword it would replace [index] instead of
index
(or another mssql keyword as well). Do you think this is the right approach or could I edit some schema where it would be replaced? I’m not sure what the right approach is or how I should do it.
b
If you are evaluating and not in production you can use this target-mssql until you get the storebrand version working. I just gave it a test and it is worked with my testing table. This target is not production ready and not as refined as the default storebrand one. You will need to set it up as a custom plugin here is the link to that documentation https://docs.meltano.com/guide/plugin-management/#custom-plugins. Here are the settings that I put in to my meltano.yaml file when I use this target.
Copy code
loaders:
  - name: target-mssql
    namespace: target_mssql
    pip_url: git+<https://github.com/BuzzCutNorman/target-mssql.git>
    capabilities:
    - about
    - stream-maps
    - schema-flattening
    - target-schema
    settings:
    - name: dialect
    - name: driver_type
    - name: host
    - name: port
      kind: integer
    - name: user
    - name: password
      kind: string
      sensitive: true
    - name: database
    - name: driver
    - name: default_target_schema
    - name: sqlalchemy_url_query
      kind: object
    - name: driver
    - name: sqlalchemy_eng_params
      kind: object
    - name: fast_executemany
    - name: future
    - name: TrustServerCertificate
    - name: batch_config
      kind: object
    - name: encoding
      kind: object
    - name: format
    - name: compression
    - name: storage
      kind: object
    - name: root
    - name: prefix
    - name: start_date
      value: '2010-01-01T00:00:00Z'
    - name: hd_jsonschema_types
      kind: boolean
    config:
e
fwiw I think bumping tap-mssql to at least singer-sdk v0.35.1 would get rid of
*'Index' is a required property* and *Failed validating 'required' in schema.*
thanks to https://github.com/meltano/sdk/pull/2225
b
ah I miss understood the error. I thought it was on the target side. There is a PR to bump tap-mssql to SDK 0.36.1. I will work of finishing my testing and merge that PR today or tomorrow.
👍 1
m
@BuzzCutNorman and @Edgar Ramírez (Arch.dev) thank you for the very quick answers and solutions to the problem. I’ll check it out tomorrow.
b
I merged the Singer-SDK 0.36.1 PR to tap-mssql and published it as the latest release. You should be able to upgrade to it if you run
meltano lock --update
then
meltano install --clean
.
🙌 1
@Michal Ďurik any luck with the new version of tap-mssql?
m
Sorry but I haven’t had time to test it yet, I’ll get to it on Friday and let you know.
b
Cool
👍 1
m
@BuzzCutNorman it works! Thank you for your effort.
🥳 2
🎉 2