MEMSql join with uniouned returns 1899 bad distributed join plan - singlestore

I have events that are inserted to table game_events and other events that are inserted to table rejected_events.
I want to union them and then do bunch of joins with other data of other tables.
I run this query directly on the memSQL console:
SELECT combinedEvents.*, win.*
FROM (
SELECT event_id, action, status
FROM events.game_events
WHERE event_arrival_time BETWEEN '2019-12-17T00:00:00Z' AND '2019-12-30T23:59:59.999Z'
UNION
SELECT event_id, action,status
FROM rejected.events
WHERE event_arrival_time BETWEEN '2019-12-17T00:00:00Z' AND '2019-12-30T23:59:59.999Z'
) AS combinedEvents
LEFT JOIN winner.winner_data AS win ON combinedEvents.event_id = win.event_id AND win.status = 'ACCEPTED'
I get from mem:
Error Code: 1889. Bad distributed join plan: leaf select contains sharded tables of multiple databases. Please contact technical support.
If I remove the JOIN - It works properly.
Any ideas?
Thanks and best regards,
Ido

It looks like it got solved on the MemSQL Forums and the solution is to move the union to the right of the join.

Related

Apache Cassandra "no viable alternative at input 'OR' "

My table looks like :
CREATE TABLE prod_cust (
pid bigint,
cid bigint,
effective_date date,
expiry_date date,
PRIMARY KEY ((pid, cid))
);
My below query is giving no viable alternative at input 'OR' error
SELECT * FROM prod_cust
where
pid=101 and cid=201
OR
pid=102 and cid=202;
Does Cassandra not support OR operator if not, Is there any alternate way to achieve my result.
CQL does not support the OR operator. Sometimes you can get around that by using IN. But even IN won't let you do what you're attempting.
I see two options:
Submit each side of your OR as individual queries.
Restructure the table to better-suit what you're trying to do. Doing a "port-over" from a RDBMS to Cassandra almost never works as intended.

SPARK SQL CREATE VIEW

I have noticed that there seems to be some max length of the create view statement. Below is a SQL query I can run (select statement). If I put a create view in front, it works as long as I limit the columns in the sub-query. The view itself would only contain one column. I have provided this for example. I am running my sql through thrift server. Is there any way to get around this issue? Thanks in advance!
Working
select p from
(
select p
from
(select p,concat(
p1,',',p2,',',p3,',',p4,',',p5,',',p6,',',p7,',',p8,',',p9,',',p10,',',p11,',',p12,',',p13,',',p14,',',p15,',',p16,',',p17,',',p18,',',p19,',',p20,',',
p21,',',p22,',',p23,',',p24,',',p25,',',p26,',',p27,',',p28,',',p29,',',p30,',',p31,',',p32,',',p33,',',p34,',',p35,',',p36,',',p37,',',p38,',',p39,',',p40,',',
p41,',',p42,',',p43,',',p44,',',p45,',',p46,',',p47,',',p48,',',p49,',',p50,',',p51,',',p52,',',p53,',',p54,',',p55,',',p56,',',p57,',',p58,',',p59,',',p60,',',
p61,',',p62,',',p63,',',p64,',',p65,',',p66,',',p67,',',p68,',',p69,',',p70,',',p71,',',p72,',',p73,',',p74,',',p75,',',p76,',',p77,',',p78,',',p79,',',p80,',',
p81,',',p82,',',p83,',',p84,',',p85,',',p86,',',p87,',',p88,',',p89,',',p90,',',p91,',',p92,',',p93,',',p94,',',p95,',',p96,',',p97,',',p98,',',p99,',',p100,',',
p101,',',p102,',',p103,',',p104,',',p105,',',p106,',',p107,',',p108,',',p109,',',p110,',',p111,',',p112,',',p113,',',p114,',',p115,',',p116,',',p117,',',p118,',',p119,',',p120,',',
p121,',',p122,',',p123,',',p124,',',p125,',',p126,',',p127,',',p128,',',p129,',',p130,',',p131,',',p132,',',p133,',',p134,',',p135,',',p136,',',p137,',',p138,',',p139,',',p140,',',
p141,',',p142,',',p143,',',p144,',',p145,',',p146,',',p147,',',p148,',',p149,',',p150,',',p151,',',p152,',',p153,',',p154,',',p155,',',p156,',',p157,',',p158,',',p159,',',p160,',',
p161,',',p162,',',p163,',',p164,',',p165,',',p166,',',p167,',',p168,',',p169,',',p170,',',p171,',',p172,',',p173,',',p174,',',p175,',',p176,',',p177,',',p178,',',p179,',',p180,',',
p181,',',p182,',',p183,',',p184,',',p185,',',p186,',',p187,',',p188,',',p189,',',p190,',',p191,',',p192,',',p193,',',p194,',',p195,',',p196,',',p197,',',p198,',',p199,',',p200,',',
p201,',',p202,',',p203,',',p204,',',p205,',',p206,',',p207,',',p208,',',p209,',',p210,',',p211,',',p212,',',p213,',',p214,',',p215,',',p216,',',p217,',',p218,',',p219,',',p220,',',
p221,',',p222,',',p223,',',p224,',',p225,',',p226,',',p227,',',p228,',',p229,',',p230,',',p231,',',p232,',',p233,',',p234,',',p235,',',p236,',',p237,',',p238,',',p239,',',p240,',',
p241,',',p242,',',p243,',',p244,',',p245,',',p246,',',p247,',',p248,',',p249,',',p250,',',p251,',',p252,',',p253,',',p254,',',p255,',',p256,',',p257,',',p258,',',p259,',',p260,',',
p261,',',p262,',',p263,',',p264,',',p265,',',p266,',',p267,',',p268,',',p269,',',p270,',',p271,',',p272,',',p273,',',p274,',',p275,',',p276,',',p277,',',p278,',',p279) vector
from table1) a
) c
Not working
CREATE VIEW TEST AS
select p from
(
select p
from
(select p,concat(
p1,',',p2,',',p3,',',p4,',',p5,',',p6,',',p7,',',p8,',',p9,',',p10,',',p11,',',p12,',',p13,',',p14,',',p15,',',p16,',',p17,',',p18,',',p19,',',p20,',',
p21,',',p22,',',p23,',',p24,',',p25,',',p26,',',p27,',',p28,',',p29,',',p30,',',p31,',',p32,',',p33,',',p34,',',p35,',',p36,',',p37,',',p38,',',p39,',',p40,',',
p41,',',p42,',',p43,',',p44,',',p45,',',p46,',',p47,',',p48,',',p49,',',p50,',',p51,',',p52,',',p53,',',p54,',',p55,',',p56,',',p57,',',p58,',',p59,',',p60,',',
p61,',',p62,',',p63,',',p64,',',p65,',',p66,',',p67,',',p68,',',p69,',',p70,',',p71,',',p72,',',p73,',',p74,',',p75,',',p76,',',p77,',',p78,',',p79,',',p80,',',
p81,',',p82,',',p83,',',p84,',',p85,',',p86,',',p87,',',p88,',',p89,',',p90,',',p91,',',p92,',',p93,',',p94,',',p95,',',p96,',',p97,',',p98,',',p99,',',p100,',',
p101,',',p102,',',p103,',',p104,',',p105,',',p106,',',p107,',',p108,',',p109,',',p110,',',p111,',',p112,',',p113,',',p114,',',p115,',',p116,',',p117,',',p118,',',p119,',',p120,',',
p121,',',p122,',',p123,',',p124,',',p125,',',p126,',',p127,',',p128,',',p129,',',p130,',',p131,',',p132,',',p133,',',p134,',',p135,',',p136,',',p137,',',p138,',',p139,',',p140,',',
p141,',',p142,',',p143,',',p144,',',p145,',',p146,',',p147,',',p148,',',p149,',',p150,',',p151,',',p152,',',p153,',',p154,',',p155,',',p156,',',p157,',',p158,',',p159,',',p160,',',
p161,',',p162,',',p163,',',p164,',',p165,',',p166,',',p167,',',p168,',',p169,',',p170,',',p171,',',p172,',',p173,',',p174,',',p175,',',p176,',',p177,',',p178,',',p179,',',p180,',',
p181,',',p182,',',p183,',',p184,',',p185,',',p186,',',p187,',',p188,',',p189,',',p190,',',p191,',',p192,',',p193,',',p194,',',p195,',',p196,',',p197,',',p198,',',p199,',',p200,',',
p201,',',p202,',',p203,',',p204,',',p205,',',p206,',',p207,',',p208,',',p209,',',p210,',',p211,',',p212,',',p213,',',p214,',',p215,',',p216,',',p217,',',p218,',',p219,',',p220,',',
p221,',',p222,',',p223,',',p224,',',p225,',',p226,',',p227,',',p228,',',p229,',',p230,',',p231,',',p232,',',p233,',',p234,',',p235,',',p236,',',p237,',',p238,',',p239,',',p240,',',
p241,',',p242,',',p243,',',p244,',',p245,',',p246,',',p247,',',p248,',',p249,',',p250,',',p251,',',p252,',',p253,',',p254,',',p255,',',p256,',',p257,',',p258,',',p259,',',p260,',',
p261,',',p262,',',p263,',',p264,',',p265,',',p266,',',p267,',',p268,',',p269,',',p270,',',p271,',',p272,',',p273,',',p274,',',p275,',',p276,',',p277,',',p278,',',p279) vector
from table1) a
) c
WORKING
CREATE VIEW TEST AS
select p from
(
select p
from
(select p,concat(
p1,',',p2,',',p3,',',p4,',',p5,',',p6,',',p7,',',p8,',',p9,',',p10,',',p11,',',p12,',',p13,',',p14,',',p15,',',p16,',',p17,',',p18,',',p19,',',p20,',',
p21,',',p22,',',p23,',',p24,',',p25,',',p26,',',p27,',',p28,',',p29,',',p30,',',p31,',',p32,',',p33,',',p34,',',p35,',',p36,',',p37,',',p38,',',p39,',',p40,',',
p41,',',p42,',',p43,',',p44,',',p45,',',p46,',',p47,',',p48,',',p49,',',p50,',',p51,',',p52,',',p53,',',p54,',',p55,',',p56,',',p57,',',p58,',',p59,',',p60,',',
p61,',',p62,',',p63,',',p64,',',p65,',',p66,',',p67,',',p68,',',p69,',',p70,',',p71,',',p72,',',p73,',',p74,',',p75,',',p76,',',p77,',',p78,',',p79,',',p80,',',
p81,',',p82,',',p83,',',p84,',',p85,',',p86,',',p87,',',p88,',',p89,',',p90,',',p91,',',p92,',',p93,',',p94,',',p95,',',p96,',',p97,',',p98,',',p99,',',p100,',') vector
from table1) a
) c
Use JDBC driver included with Spark. I can compile view now. I am using SQL
Use SQL Squirrel instead with JDBC driver to connect and run queries. I was using the Microsoft SPARK ODBC driver. the JDBC one works fine.

how to make a subselect in cassandra db

I'm trying to recover the last state of my object, but this sub select does not work, I've seen that the new version of cassandra db supports aggregate operations and subqueries.
select * from event_store
where event_version = (select max(event_version) from event_store)
ALLOW FILTERING;
SyntaxException: line 1:49 no viable alternative at input 'select' (...from event_store where event_version = [(]select...)
You can do this by using 2 separate queries:
select max(event_version) from event_store;
and then
select * from event_store where event_version = 2 allow filtering;
I might be a bit outdated but it looks like there is no sub select support:
Work on this ticket is stopped
https://issues.apache.org/jira/browse/CASSANDRA-8846
There were some attempts to do this:
https://github.com/jobmthomas/Cassandra-SubQuery
But overall this is just not supported in cassandra.

Composite key in Cassandra with Pig

We have a CQL table that looks something like this:
CREATE table data (
occurday text,
seqnumber int,
occurtimems bigint,
unique bigint,
fields map<text, text>,
primary key ((occurday, seqnumber), occurtimems, unique)
)
I can query this table from cqlsh like this:
select * from data where seqnumber = 10 AND occurday = '2013-10-01';
This query works and returns the expected data.
If I execute this query as part of a LOAD from within Pig, however, things don't work.
-- Need to URL encode the query
data = LOAD 'cql://ks/data?where_clause=seqnumber%3D10%20AND%20occurday%3D%272013-10-01%27' USING CqlStorage();
gives
InvalidRequestException(why:seqnumber cannot be restricted by more than one relation if it includes an Equal)
at org.apache.cassandra.thrift.Cassandra$prepare_cql3_query_result.read(Cassandra.java:39567)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_prepare_cql3_query(Cassandra.java:1625)
at org.apache.cassandra.thrift.Cassandra$Client.prepare_cql3_query(Cassandra.java:1611)
at org.apache.cassandra.hadoop.cql3.CqlPagingRecordReader$RowIterator.prepareQuery(CqlPagingRecordReader.java:591)
at org.apache.cassandra.hadoop.cql3.CqlPagingRecordReader$RowIterator.executeQuery(CqlPagingRecordReader.java:621)
Shouldn't these behave the same? Why is the version through Pig failing where the straight cqlsh command works?
Hadoop is using CqlPagingRecordReader to try to load your data. This is leading to queries that are not identical to what you have entered. The paging record reader is trying to obtain small slices of Cassandra data at a time to avoid timeouts.
This means that your query is executed as
SELECT * FROM "data" WHERE token("occurday","seqnumber") > ? AND
token("occurday","seqnumber") <= ? AND occurday='A Great Day'
AND seqnumber=1 LIMIT 1000 ALLOW FILTERING
And this is why you are seeing your repeated key error. I'll submit a bug to the Cassandra Project.
Jira:
https://issues.apache.org/jira/browse/CASSANDRA-6151

Why is GetPaged() Executing two database calls?

I'm a bit new to subsonic (i.e. evaluating 3.0.0.3) and have come across a strange behavior in GetPaged(int pageIndex, int pageSize). When I execute the method it does two SQL calls. Any ideas why ?
Details
Lets say I have a "Cultures" table with 200 rows. In my code I do something like ...
var sonicCollection = from c in RTE.Culture.GetPaged(1, 25)
select c;
Now, I would expect this executes a single query returning the first 25 entries in my cultures table. When I watch SQL profiler I see two queries run by.
First this--
SELECT [dbo].[Cultures].[cultureCode], [dbo].[Cultures].[cultureName]
FROM [dbo].[Cultures]
Then This--
SELECT *
FROM (SELECT ROW_NUMBER() OVER (
ORDER BY cultureID ASC) AS Row,
[dbo].[Cultures].[cultureCode], [dbo].[Cultures].[cultureName]
FROM [dbo].[Cultures]
)
AS PagedResults
WHERE Row >= 1 AND Row <= 25
I expect the 2nd query to roll by, as it is the one returning the 25 rows I politely requested of subsonic. The first query, however, appears to return 200 rows (at least according to SQL profiler).
Any ideas what's going on?
It's a bug in the code. The code actually queries every record and then iterates over each one for the count. I've created an issue in the github repo here:
https://github.com/subsonic/SubSonic-3.0/issues/259
You can download the source, fix the issue and recompile pretty easily. I've done this and its fixed my issue.
You just want to use RTE.Culture.GetPaged() - it runs the paged query for you.

Resources