Installed:
- Cassandra 3.11.9
- ODBC DataStax Cassandra 2.6 64-bit (Win10)
- MSSQL 2019
In MSSQL Linked Server to Cassandra.
Create simple table in COMMUNITY keyspace.
cqlsh> create KEYSPACE community ... WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; cqlsh> use community ; cqlsh:community> create TABLE odbctest( ... id uuid PRIMARY KEY, ... dt date, ... vl int ... ); cqlsh:community> insert INTO odbctest(id,dt,vl) ... values(91451832-74f7-4709-b180-7cb526184280,'2020-04-16',1); cqlsh:community> select * ... from odbctest ... where id=91451832-74f7-4709-b180-7cb526184280; id | dt | vl --------------------------------------+------------+---- 91451832-74f7-4709-b180-7cb526184280 | 2020-04-16 | 1
Edit cassandra.yaml
... enable_user_defined_functions: true enable_scripted_user_defined_functions: true ...
Create simple UDF.
cqlsh:community> CREATE FUNCTION myUDF(input int) ... CALLED ON NULL INPUT RETURNS int ... LANGUAGE javascript ... AS 'input'; cqlsh:community> select id,dt,vl,myUDF(vl) as udf_result from odbctest ; id | dt | vl | udf_result --------------------------------------+------------+----+------------ 91451832-74f7-4709-b180-7cb526184280 | 2020-04-16 | 1 | 1
Everything works
Now on the MSSQL side.
The first problem I encountered was quotation marks. MSSQL doesn't understand UUIDs without quotes.
It works with quotation marks.
I want to use a UDF in the request. Error.
OLE DB provider "MSDASQL" for linked server "CASSANDRA" returned message "[DataStax][CassandraODBC] (10) Error while executing a query in Cassandra: [33563136] : Invalid STRING constant (91451832-74F7-4709-B180-7CB526184280) for "id" of type uuid".
Removing the filter for ID. Error.
I tried using MIN(), MAX(), AVG()
cqlsh:community> select ... min(vl) as minFn, ... max(vl) as maxFn, ... avg(vl) as avgFn ... from odbctest ... where id=91451832-74f7-4709-b180-7cb526184280; minfn | maxfn | avgfn -------+-------+------- 1 | 1 | 1
In MSSQL it works!
I tried using WRITETIME()
cqlsh:community> select ... id, dt, vl, ... writetime(vl) as wt_vl ... from odbctest ... where id=91451832-74f7-4709-b180-7cb526184280; id | dt | vl | wt_vl --------------------------------------+------------+----+------------------ 91451832-74f7-4709-b180-7cb526184280 | 2020-04-16 | 1 | 1607555089708000
MSSQL - Error.
The entire text of the error:
OLE DB provider "MSDASQL" for linked server "CASSANDRA" returned message "[DataStax][CassandraODBC] (10) Error while executing a query in Cassandra: [33563136] : Invalid STRING constant (91451832-74f7-4709-b180-7cb526184280) for "id" of type uuid". Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing the query " select id, dt, vl, writetime(vl) as wt_vl from community.odbctest where id='91451832-74f7-4709-b180-7cb526184280' " for execution against OLE DB provider "MSDASQL" for linked server "CASSANDRA".
My ODBC settings
Changing the "query mode" parameter does not give results.
Как решить проблему вызова UDF?