In ClickHouse Playground dataset conditions on UInt64 fields don't seem to work. For example query:
SELECT * FROM hits_100m_obfuscated where WatchID = 8120543446287443000
doesn't return anything (even though I copied the ID from the dataset). Same is true if the condition is on UserID. But the following works just fine:
SELECT * FROM hits_100m_obfuscated where ClientIP = 3078276782
I guess the reason is that ClientIP field has type UInt32, but both UserID and WatchID - UInt64. I tried to use toUInt64 and CAST, but didn't succeed.
Any idea what am I doing wrong?
seems web/frontend issue
SELECT '- '||toString(max(WatchID))||' -', max(WatchID), toString(max(WatchID)) FROM hits_100m_obfuscated
- 9223372033328793741 - | 9223372033328794000 | 9223372033328794000
https://github.com/ClickHouse/ClickHouse/issues/10824
It looks like it is a bug of Playground.
As a temporary workaround, you can send a direct request to service endpoint using the favorite HTTP API client such as Postman, Fiddler, curl etc:
curl "https://play.clickhouse.tech/api/v20.3/?database=datasets&user=playground&password=clickhouse&query=SELECT+*+FROM+hits_100m_obfuscated+where+WatchID=8927014313511165737+limit+1+format+Vertical"
Related
So I'm doing some tests with GraphQL, and I'm failing in doing something that I believe is fairly simple.
When going to the GraphQL demo site (https://graphql.org/swapi-graphql) I'm presented with a default query which goes like this:
{
allFilms {
films {
title,
director,
releaseDate
}
}
}
This works as expected and returns a list of films.
Now - I would like to modify this query to return only the films where the director is George Lucas, and for the life of me - I can't figure out how to do that.
I've tried using the where and filter expressions, and also change the second line to films: (director: "George Lucas") but keep getting error messages.
What's the correct syntax for doing that?
Thanks!
If you check the docs of the provided GraphQL schema, you'll see that this is not possible. Following is the definition of the allFilms field:
allFilms(
after: String
first: Int
before: String
last: Int
): FilmsConnection
As per the doc, it has 4 input arguments, which are after, first, before, and last. There is no way to filter this out using the director's name.
GraphQL is not SQL. You cannot use expressions like WHERE or FILTER in GraphQL. The schema is already defined and the filters are pre-defined too. If the schema does not allow you to filter values using a certain field, you just can't do it.
You can to see the graphql schema here https://github.com/graphql/swapi-graphql/blob/master/schema.graphql
The allFilms query does not contain a filter for the field director. Also i can't find other query with this filter.
Most likely you need to write a filter on the result of the query.
So, the thing is, I'm trying to query a GSI table on DynamoDB and get a really weird behaviour.
The main table schema is as follows
- Partition key: test_id (string)
- Sort key: version (string)
- Other attributes (createdAt, tags, etc)
I want to obtain every entry that has a sort_key equal to v0_test WITHOUT filtering by partition key. To do this and avoid a full scan I created a GSI (Global Secondary Index) as follows:
- Partition key: version (string)
- Sort key: createdAt (number)
- Other attributes (test_id, tags, etc)
When querying this from AWS console I can query for every partition key equal to v0_test and I get the expected results, but when I query from inside a lambda function (runtime: nodejs16.x) I get an error.
The code for the query is as follows:
const dynamoDb = new AWS.DynamoDB.DocumentClient();
let params = {
TableName: dynamoTable,
IndexName: dynamoTableIndex ,
KeyConditionExpression: 'version = :v0 AND createdAt BETWEEN :tLower AND :tUpper',
ExpressionAttributeValues: {
':v0': 'v0_test',
':tUpper': Math.floor(Date.now() / 1000).toString(),
':tLower': '0'
}
};
let result = await dynamoDb.query(params).promise();
console.log("Success", result);
And the error I get is
ERROR ValidationException: Query condition missed key schema element: test_id
As you can see it's asking for the partition key for the main table.
Things I've tried:
Using AWS.DynamoDB instead of AWS.DynamoDB.DocumentClient. Same error
Changing version for test_id in the query. Got ERROR ValidationException: Query condition missed key schema element: version
Sending both version and test_id on KeyConditionExpression. Got the following error:ERROR ValidationException: KeyConditionExpressions must only contain one condition per key
New Dynamo table, new GSI. Same errors
I wasn't expecting that at all. It's my first time using DynamoDB but as I understand it the idea behind GSI's (or one of them) is to be able to query a DynamoDB table by other attribute than it's main partition key without having to do a full scan.
Any help appreciated and if you need more details just ask! It's my first time asking on StackOverflow too so I'm sure I'll miss something.
EDIT
Tested the suggested solution and got an error suggesting that the schema was wrong, which was a new error and got me thinking, so I tried specifying the ExpressionAttributeNames and it WORKED!.
I created the request as follows using DocumentClient:
const dynamoDb = new AWS.DynamoDB.DocumentClient();
let params = {
TableName: 'CLASSIFIER_TESTS_DEV_us-east-1',
IndexName: 'version-createdAt-index',
KeyConditionExpression: '#versionAttr = :version AND #ca BETWEEN :tLower AND :tUpper',
ExpressionAttributeNames: {
"#versionAttr": "version",
"#ca": "createdAt"
},
ExpressionAttributeValues: {
":version": "v0_test",
":tUpper": Date.now(),
":tLower": 0
}
};
let result = await dynamoDb.query(params).promise();
Thanks everyone!
I still think that it should have worked the way I did it the first time as that's the way everyone does it on tutorials/examples/documentation, but oh well, got it working and that's what matters for now.
This should not be an issue. I would suggest the following:
Test locally, have your DynamoDB API call run from your local machine, this will ensure that no issues are being caused by Lambda invocations
Hard code your TableName and IndexName as strings in your parameters.
If the above is still causing an issue, try the same logic but this time a Query from the base table.
Let me know if you still face issue after that, happy to help.
I am working on an api which takes in parameters for filters (as given below)
/api/endpoint?filter_key_1=filter_value_1&...
I've previously worked on spring where the criteria API allows for dynamically building SQL queries without much hassle. In golang I'm using gorm for handling the ORM operations. Is there anyway to build the queries with optional parameters without writing redundant code?.
For example:
If the request sent is:
/api/endpoint?fk_1=fv_1&fk_2=fv_2&fk_3=fv_3
Query generated should be :
select * from table where fk_1 = fv_1 AND fk_2 = fv_2 AND fk_3 = fv_3
but in case of :
/api/endpoint?fk_1=fv_1
Query generated should be:
select * from table where fk_1 = fv_1
Currently my approach is to check if each variable is present and build the query as a string :
query:="select * from table where "
if fk_1 != ""{
query += "fk_1 = fv_1"
}
... and so on
but this seems very awkward and error prone
Any help will be appreciated! Thanks
EDIT
Building on #bjornaer's answer what helped me was to get the map[string][]string in a form that I can send the same to gorm, map[string]interface{}.
This thread will help in the same.
Now there's no longer a need for redundant checks or string operations in the filters
so it seems to me your question has 2 parts:
you need to retrieve your query values from your url and
insert them to your db query
I don't see how you are handling your requests so let's assume you use the http package: from req.URL you get the URL object and from that calling the Query() method yields a map[string][]string of your query parameters, with those in a variable URLQuery let's pause and look at how you query with gorm:
db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{
QueryFields: true,
})
here I open a sqlite, then you can pass a variable reference to fill with your query, for example:
result := db.Where(map[string]interface{}{"name": "jinzhu", "age": 20}).Find(&users)
now from the example above, replace your variable in:
result := db.Where(map[string]interface{}URLQuery).Find(&users)
you can find it in the docs
I am trying to make a request that takes a variable for the distinct_on parameter, but what I have doesn't seem to work:
query customers($distinct: String!) {
customers(limit: 20, distinct_on: $distinct) {
startDate
endDate
}
}
I am assuming the String type is not what is expected, what type should I be using for $distinct?
The type for your variable will be a table-specific enum as documented here.
Your entire schema should be viewable through the GraphiQL interface of the Hasura console -- you can use this to lookup types for fields and arguments. You can also check the error returned by the server -- it will include details about what went wrong with your query, including the type that was expected.
I am trying to get a list of all connections where the SI_SESSION_USER='xyz'.
When I do a query like
select * from si_infoobjects where si_id='00000', I can see this field in the results with that value (xyz).
When I modify the query to look for that specific field and value, it returns zero rows.
I am using:
select * from si_infoobjects where SI_SESSION_USER='xyz'
What query will return the correct results?
Just a guess here, but si_session_user is probably in the Processing Info bag. So use this:
select *
from ci_infoobjects
where si_processinfo.SI_SESSION_USER='xyz'
Note that that's ci_infoobjects not si_infoobjects, but I assume that's just a typo in your question.