Is it possible to pass query parameters in the request body for Clickhouse's http interface? - clickhouse

According to the docs, the Clickhouse's http interface allows me to pass query parameters in a query string like this:
First, I can write a query with a parameter:
SELECT * FROM foo WHERE id = {id:text}
This query is passed in the body request, and the value for id is passed in the query string as follows:
http://clickhouse-host:8123/param_id=1
However, I wonder if there's a way to pass both the query and its parameters in the body request. I could not find how to achieve this in the docs.

Related

Implementing filters in ORM golang

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

Validate the JDBC request with a user defined variable

I am new to JMeter,
In my test I am creating a JDBC Connection to oracle DB and running a query which fetching me the count of records, which I want to validate must be equal to the SAMPLE-NUMBER (which is a defined variable in the user defined variable).
SELECT COUNT(*) FROM event_log WHERE audit_context_key LIKE '288017ec-0dcf-4fd5-9565-e8ad15e65cd2' AND event_desc = 'Success'
Response Body:
COUNT(*)
2
UserDefined Variable
You can do this, defined the variable name in JDBC request,
for example, TOTALCOUNT and add a JSR223 Assertion with the following code,
1.upto(vars.get('TOTALCOUNT_#') as int, {
if (vars.get('TOTALCOUNT_' + it) == '${__groovy(vars.get('SAMPLE-NUMBER'),)}') {
AssertionResult.setFailure(false);
}
})
Response Assertion can do the trick for you:
In the JDBC Request define "Variable Names", i.e. ACTUAL_COUNT
Once done you can compare the ACTUAL_COUNT variable value with the SAMPLE-NUMBER variable like:

Jmeter : How to get first userID from first request and transfer to second request same userId?

I have a script include two HTTP request
1 The first request is User Authentication。include userId.....
2: the second request also includes userId.
The two parameters are consistent。
How to get the first userID from the first request and transfer to second request same userId?
I want to get userID from the first request, not from the response, response body does not include userId, transfer the same userId to the second request.
Here is the first request body:
[
{"productId":"5551",
"userId":"${__RandomString(32,44e00d674dee4ff7a2d4f0081991b6d40Bs9Hc)}",
"service":"200008",
"app_system":"7.1.1",
"equipmentId":"866935038314977",
"app_devicetype":"vivo X20A",
"app_platform":"Android",
"app_version":"3.1.3",
"market":"icash_main"}
]
Use Extractors for the co-relating your requests and responses.
First, you need to extract the userID from the response of your 1st requests.
To do this, choose an extractor (Use JSON Extractor if your requests return the JSON response) and add to your 1st request.
Second, After getting the value of userId through a variable using the extractor, you can use it in your subsequent requests.
Edit:
As you want to use the same userId in both requests, use User Defined Variables in your test plan and add a variable userID in it like this:
In your request body use the variable of userId like this:
{"productId":"5551",
"userId":"${userId}",
"service":"200008",
"app_system":"7.1.1",
"equipmentId":"866935038314977",
"app_devicetype":"vivo X20A",
"app_platform":"Android",
"app_version":"3.1.3",
"market":"icash_main"}
Here is the requests body of the two requests which are using the same userId
Body of the Request 1:
Body of the Request 2:

jmeter jdbc request parameter type

I am constructing a jmeter jdbc Prepared Select statement request.
I have the query as,
select * from tableName where c=?
Parameter Value: ${columnId}
Parameter Type: LONGVARCHAR
When I run I get a: type mismatch error UNSIGNED_LONG and CHAR for c='1234'
I need to pass a long value here. Also, how would I pass a binary array?
You should use User defined variables as reference. This way you can avid using Parameter fields.
Reference: http://jmeter.apache.org/usermanual/functions.html
select * from tableName where c='${columnId}'

how to pass multiple values to query using jdbcTemplate in spring

In my Spring Hibernate application i have all the sql queries in one common_queries.xml file,where some queries require 2 to 3 parameters shown as below
<query id="mining.fuel" no-of-params="2">
select ms.id id,ms.name value,concat(ms.name,' ',' (',ms.code,')') label,ms.rate rate from mining_fuel ms where ms.name like '?' and ms.fuel_type_id=? LIMIT 10
</query>
In my daoImpl i get this query
lookupList = jdbcTemplate.queryForList(q1.getQuery());
I will get the query here,but how to pass the value of '?'s here, i have those 2 values with me in daoImpl.. pl send the code of how to achieve this.I dont want to use prepared statement.
Use this overload which takes an Object vararg for passing the query parameters:
lookupList = jdbcTemplate.queryForList(q1.getQuery(), value1, value2, value3);
I think that you only need to create an Object array with the params used by the query, take in mind that the order is important because value1 will be the first replacement for ? in the query.
lookupList = jdbcTemplate.queryForList(q1.getQuery(), new Object[]{value1, value2, value3});
First calls the queryForList method on jdbctemplate reference and pass query and object type array in this object type array we must pass only objects means if we have id it is int type we have to convert to object type while putting inside object array.
lookupList = jdbcTemplate.queryForList(q1.getQuery, new Object[]{designation, new Integer(id), new Float(sal)}

Resources