How to impelement the update #Query with IN operator while using spring data cassandra? - spring-data-cassandra

Could anyone help please.
I need to know How to impelement the update #Query with IN operator while using spring data cassandra?
Because I want to use something like this:
#Query("UPDATE objects SET children = ?0 WHERE id IN (?...)")
Ofc if it's possible. Might be I should use native data stax template for this kind of query.
Thx in advance

I am not sure how to implement it, but it is not recommended to use IN in queries with Cassandra ( see this blog for example). It will actually be slower than iterating through the ids and and calling update separately for every id using the standard query, e.g.
#Query("UPDATE objects SET children = ?0 WHERE id = ?1")

Related

Fetch all tables in a particuler Postgres database using node?

I need to fetch all tables in a particular Postgres database using node. But not finding any way to achieve that. Is there any way to get that?
For example, suppose I have a database named 'TestDatabase' it contains 4 tables( just assume it can have less or more) Person, Company, Clothes, Animal.
I need to get the name of all of them using node.
I am also using node-postgres ('pg') to connect with the database.
As an alternative you can use information_schema. It is not better then the pg_* objects in the system catalog but is standardized and more portable. Here it is:
select table_schema||'.'||table_name as table_fullname
from information_schema."tables"
where table_type = 'BASE TABLE'
and table_schema not in ('pg_catalog', 'information_schema');
The system objects have been filtered by this expression
table_schema not in ('pg_catalog', 'information_schema')
You can further modify it to only include schemas that you need.
This is a generic solution. Use the query below:
SELECT
relname
FROM
pg_class
WHERE
relkind = 'r';
pg_class is the system catalog that holds information on table like objects. Hence the need to restrict relkind to 'r'. This will include all table types. To further restrict see relpersistence at link below.
https://www.postgresql.org/docs/current/catalog-pg-class.html

Nested query on Dynamodb with nodejs

I am working on a project where i need to perform nested query over Dynamodb tables. Please let know if it is possible if yes then please provide a sample for id not in(select id from table) in node js
Not supported. Select your id`s first and only then use it...

DocumentDB ORDER BY removing undefined

I have a data set containing legacy data. We are sorting by a field which is only present in newer documents.
When I sort by this field, only the objects which have this value are returned, even when they pass the WHERE clause.
How do we get a sorted set at the top for objects which have the field, and all those that don't are un-sorted at the end?
I've been trying something like this, but it's not valid:
SELECT T.id, IS_DEFINED(T.createdDate) ? T.createdDate : "2000-01-01T00:00:00" AS createdDate FROM Themes T
WHERE T.customerId = 43333
AND T.isDefault = false
AND (NOT IS_DEFINED(T.isArchived) OR T.isArchived = false)
ORDER BY createdDate ASC
I have also tried:
SELECT T.id FROM Themes T
WHERE T.customerId = 43333
AND T.isDefault = false
AND (NOT IS_DEFINED(T.isArchived) OR T.isArchived = false)
ORDER BY IS_DEFINED(T.createdDate) ? T.createdDate : "2000-01-01T00:00:00" ASC
Short of populating that field in documents where it's missing, the only way I know to do it would be to return all of the data and do the sort client side.
I wonder if you could ORDER BY a projected field and/or if you can use SQL's case and value substitution features in DocumentDB's SQL subset... and if so, are they efficient?
The bottleneck for my system is DocumentDB RUs so I try to do as much as possible client-side, but I'd love to know if this is possible and efficient in DocumentDB's SQL.
In the schema-less databases, there is no defined convention on the type order, let alone on the undefined entries when sorting. Your requirement is still valid nonetheless.
Currently the best solution for this in DocumentDB, is to do two part queries -
Look for NOT IS_DEFINED documents
Query for ORDER BY
If the number of documents without the isArchived property are few and fixed, then it might be a good idea to prepare that list and keep it in a separate document so that the first query is much faster once the document is built one time. All you need is to query that documents by "id" for all the entries in that metadata document and retrieve them first.

Debug a Subsonic Select Query

I've got a Subsonic query that isn't returning any values. I think the problem is in my where clause, although I'm not sure why.
What I'm really looking for is a way to debug the query to see the SQL that's actually being spit out by Subsonic. I know there was a way to do this with the Query object with Inspect(), but I'm using Select objects (or could also probably use SQLQuerys) because I need joins. Is there any inspect() type option for a Subsonic Select?
Here's the code I'm using:
Dim qry As New [Select]("Contract_NO")
qry.From(<table1>.Schema)
qry.InnerJoin(<table2>.<table2columnA>, <table1>.<table1columnA)
qry.Where(NonInfoleaseLessor.Columns.LessorCode).Like("mystring")
If I comment out the where line, I get a full list of results. It doesn't like something about it, but I've manually run the query at the database with that where clause, and it works. How can I see what the difference is?
The problem with your query is that you should be using Contains("mystring") instead of Like("mystring").
The best way to see the SQL is to use the BuildSqlStatement() method of the query.
Use [a] profiler to see what SQL is actually being executed against the database.
As Adam spotted:
.Like("mystring")
should most probably be
.Like("%mystring%")
please try using Like("%mystring%")
It might have something to do with your choice of clause, or which column name you are using. Subsonic has a couple of column name field
OBJECT.xyzColumn
OBJECT.xyzColumn.QualifiedName
OBJECT.Columns.xyz
I have had to play with these in the past to get the values I wanted.

ExecuteJoinedDataSet but with Where()

I did some searching and see that ExecuteJoinedDataSet will not work with the Where clause in 2.1. If I want to query a table with WHERE, but want the FK objects values to be bindable is the easiest way to just create a custom class(my table has tons of FK references).
Could you give us an example of what kind of query you are trying to write? If you are just trying to return a DataTable without creating a custom class just write your query and use the ExecuteReader which Returns an IDataReader. The IDataReader is bindable and if you need more you can just load it into a DataTable.

Resources