Cassandra INSERT Column Set<text> Does Not Persist - jdbc

The problem is that when I INSERT a row into a Cassandra table. A column(ciderblocks) does not appear to be persisting. No exception is generated. Following is my schema,
CREATE TABLE atlascarpenter.registration (
id timeuuid PRIMARY KEY,
email text,
firstname text,
lastname text,
cidrblocks set<text>
);
My insert is this,
INSERT INTO atlascarpenter.registration
(id, cidrblocks, email, firstname, lastname)
VALUES
(now(), {'222.222.222.0/10','111.111.111.0/10'}, 'john.doe#google.com', 'john', 'doe');
My query and results are this,
select * from atlascarpenter.registration
id, cidrblocks, email, firstname, lastname
54ca6860-6b47-11e6-8ddf-c9ea2c0bd7d2 [] jane.doe#company.com jane doe
Any idea why cidrblocks is empty?

Turns out the problem is RazorSQL. If I dump the schema or the contents of the table using Cassandra's cqlsh tool I see correct schema and data as expected. RazorSQL's tool indicated it was compatible with Cassandra but unfortunately it does not appear to support all Cassandra data types. Or at least it does not support multi-valued types like list and set. Strange I'm posting my own reply as an answer but I thought this might be helpful to someone else.

Related

NIFI - How to insert distinct data from the flow and refer to that data ID in other places

I'm trying to learn NIFI so this is all new to me, I used to work with Talend and I have hard time translating to NIFI. So the main idea: For example is I have two tables in Postgresql
Table CITY :
ID (auto generated), city_name
Table PERSON :
ID (auto generated), first_name, last_name, city_id
and I have a CSV file :
first_name, last_name, city_name
Can you please explain how I can insert in tow tables from one flowfile and refer in the table PERSON to the ID of the city not the name from the table CITY.
Thank you
you could use LookupRecord to enrich each record with city id and split input in two files: matched/unmatched.
for matched you have to execute simple insert into PERSON table - because city id was found.
for unmatched you have to generate insert/upsert into CITY table and then route all those records to lookup record again.
or you could insert everything as is into temp table with structure that matches your CSV.
and then execute 2 simple sql statements:
populate missing cities from temp table
insert into person from temp table with lookup city id on the level of SQL server

GraphQL Mutation Insert using Inner Query

How can I perform the following SQL Insert Query as a GraphQL Mutation Insert?
INSERT INTO User (id, name, user_type_id)
VALUES
(1, "Name", (SELECT id FROM UserType WHERE user_type="Guest"))
Provided that there is a One to Many relation from UserType table (id column) to User table (user_type_id column).
You should checkout an ORM that work with your technology.
like 'sequelize' for example.

Run SQL through JDBC, how to parameterize Table Names

If I have two tables:
CREATE TABLE Test_Persons_A
(
PersonID int,
LastName varchar(255),
FirstName varchar(255)
);
INSERT INTO Test_Persons_A (PersonID, LastName, FirstName)
VALUES (11, 'LN_A1', 'FN_A1');
INSERT INTO Test_Persons_A (PersonID, LastName, FirstName)
VALUES (12, 'LN_A2', 'FN_A2');
CREATE TABLE Test_Persons_B
(
PersonID int,
LastName varchar(255),
FirstName varchar(255)
);
INSERT INTO Test_Persons_B (PersonID, LastName, FirstName)
VALUES (21, 'LN_B1', 'FN_B1');
INSERT INTO Test_Persons_B (PersonID, LastName, FirstName)
VALUES (22, 'LN_B2', 'FN_B2');
commit;
The effect I want to achieve is equivalent to executing each the following two queries from java code through JDBC (oracle)
Block A:
select PersonID as PID, LastName as LN, FirstName as FN
from Test_Persons_A tp
where tp.LASTNAME like '%1%'
Block B:
select PersonID as PID, LastName as LN, FirstName as FN
from Test_Persons_B tp
where tp.LASTNAME like '%2%'
You can see that the only difference are:
Table Name
LASTNAME cretiria
But in my case, each of the the blocks are in fact a huge 'With...Select...' clause, and the java code (legacy, I can't change an iota) in fact reads each sql block from a .sql file as below before executing it through JDBC.
hugeQueryA.sql
hugeQueryB.sql
My question is: to avoid duplicating this huge block of code, instead, is it the best to construct a single large stored procedure (or functions)?
hugeStoredProc
put it in my DB, then construct two simple sql
simpleQueryA.sql
simpleQueryB.sql
to call the stored procedure with parameters (specified in each of the sql)?
Can I do this without having to use Dynamic SQL (since to do that I assume I will need change the content of the original huge sql files into strings and handle all the special chars - plus, would that also going to look awful?)?
More generally, when I need to 'parameterize' the table name, and can't use 'substitution variables', is dynamic SQL the only way to go?
Table names can't be parameterized, but you can use string substitution to generate the desired SQL after loading in your .sql file(s), provided the table names you're substituting in aren't based on user input.
For example, you could change:
from Test_Persons_A tp
to:
from {TableName} tp
After you load the file, use string substitution to replace "{TableName}" with the actual table name, then execute.

Oracle to retrieve data

I have table with id, name, update_date etc. columns.
Select distinct id from table1 order by update_date desc;
In above query am getting duplicate values as well. I need to retrieve distinct id with having latest updated date.
Generally speaking, this might do the job:
select id,
max(update_date) max_update_date
from table1
group by id;
as
MAX will return the latest UPDATE_DATE
GROUP BY will return DISTINCT ID's anyway (so you don't have to specify it)
If it does not, provide test case and explain what output you'd want to get; someone will assist.

alter table statements to enforce entity integrity

He guys I have the following the tables for ORACLE 10g and the problem is i am trying to enforce entity integrity on ALL tables. I have completed the first 4 but the last one is throwing an error. I have used the following code to alter the tables:
ALTER TABLE name ADD CONSTRAINT name PRIMARY KEY (name);
Actor (actorID, lastName, firstName, middleName, suffix, gender, birthDate, deathDate)
Movie (movieID, title, year, company, totalNoms, awardsWon, DVDPrice, discountPrice)
Quote (quoteID, quote)
Role (roleID ,roleName ,gender ,actorID* ,movieID*)
RoleQuote (roleID*, quoteID*)
for the last table (RoleQuote) i have tried
ALTER TABLE name ADD CONSTRAINT name, name PRIMARY KEY (name, name);
but it is throwing this error:
invalid identifier
Can anyone help me thanks the tables have been created without error and they work flawless but the constraint on the last table (RoleQuote)is not working.
ALTER TABLE table_name ADD CONSTRAINT Constraint_name PRIMARY KEY (Field1_name, Field2_name);

Resources