Define query in talend context using tSystem component - talend

I am trying to run an impala command using the tSystem component in Talend Studio. I am able to run the command in terminal .
impala-shell -i hostname:21000 -d default -k --ssl -q "COMPUTE STATS DEFAULT.TABLENAME;"
I tried to apply the same command in tSystem component. so, the command in TOS will be appied by this way:
In Talend context:
hostname = hostname:21000
database = default
tablename = default.tablename
Impala command I defined in tSystem component:
"impala-shell -i context.hostname -d context.database -k --ssl -q "COMPUTE STATS context.tablename;""
However, I got an error for this line -> -q "COMPUTE STATS context.tablename;"
Error:
Is there any ways I could use the string query in my impala command using tSystem component in TOS? Appreciate any helps. Thanks.

Yes, you just need to concatenate the context variables with your query string:
"impala-shell -i " + context.hostname + " -d " + context.database + " -k --ssl -q \"COMPUTE STATS " + context.tablename + ";\""

Related

Use [DB] for Mongodb with shell

I am researching now the simple "use" command for the mongo command. Please help me.
I just want save the my query in a file, but before that i need to connect to a certain database. For that i tried to find a "use" command like in sql, but could not find anything.
I just want to execute something like
mongo ....--use [db] --eval 'db.find' > save.query
In your question, you didn't specify what platform you're using, are you using Linux? Windows? Anyway, if you want to use the command line for mongo db then I would recommend to use the mongodb shell. Download the mongodb shell https://www.mongodb.com/try/download/shell and select what platform you're using.
https://www.mongodb.com/docs/mongodb-shell/run-commands/#mongosh-usage
That sais you have use <database> command
I just got it. You can just add the database name:
mongo [dbname] --host etc.
and it worked.
This is the easiest way in linux:
Option 1 ( command line params )
echo "db.exampleollection.find({}).forEach(function(d){printjson(d)})" | mongo --quiet exampledatabase --host "examplehost" --port "examplePort" --authenticationDatabase=admin -u "exampleuser" -p "examplepassword" > output.json
Explained:
Send the command you need to execute via echo to the mongo shell and redirect the output to the result file.
Add the option --quiet to suppress the shell printed info
You can provide the database directly in as comman line argument.
Option 2 : same way but URI format:
echo "show collections" | mongo "mongodb://user:pass#host:port/database?authSource=admin" --quiet

Kubernetes mongo DB user creation

I am trying to create a Mongo db user using the following method via Jenkins Job
kubectl exec -i ${POD} -- sh -c "mongo --eval 'db.createUser({user:"DBusernmae",pwd:"test",roles:[{role:"dbAdmin",db:"training"}]})'"
receiving following error
2021-02-09T10:50:38.641+0000 E QUERY [js] ReferenceError: DBusernmae is not defined :
Please help me on this
You have to use proper quotation: your first " starts with mongo and ends with DBusernmae
You need to escape the quote ":
kubectl exec -i ${POD} -- sh -c \
"mongo \"mongodb://admin:pwd#localhost:27017\" --eval 'db.createUser({user:\"DBusernmae\",pwd:\"test\",roles:[{role:\"dbAdmin\",db:\"training\"}]})'"
I'd be grateful if somebody found a nice way to do this that doesn't require the community or enterprise operators though.

postgres script silently pass without any result

i am trying to execute psql queries from the bash command line passing password in following format
set PGPASSWORD=rtttttul psql -U ostgres -h localhost -d postgres -c "select * from logs" -o output.txt
Somehow my queries are not giving any results.i have tried to pass different queries or incorrect credentials but still script execute without any error.
If i don't pass password and try logging in to command prompt,everything works fine.
i want to check what basic thing i am missing above
Below command worked
PGPASSWORD=rtttttul psql -U ostgres -h localhost -d postgres -c "select * from logs" -o output.txt
remove set at start of command fixed it

syntax error at or near ":" when running parametrized query from shell

I'm trying to run a parameterized query from shell.
But when I run:
p='some stuff'
psql -d "dbname" -v v1="$p" -c "SELECT * FROM table WHERE name=:'v1'"
I'm getting the following error:
ERROR: syntax error at or near ":"
Meanwhile:
psql -d "dbname" -v v1="$p" -c "\echo :'v1'"
works normally. (returns as expected: 'some stuff')
You cannot use the variable defined in -v in -c command (see below). Try passing the command into the standard input:
psql -d "dbname" -v v1="$p" <<< "SELECT * FROM table WHERE name=:'v1'"
From the document:
-c command
--command command
...
command must be either a command string that is completely parsable by
the server (i.e., it contains no psql-specific features), or a single
backslash command.
...
-v does set the psql's internal variable, which is psql-specific features. That's why you got the syntax error.

Save Impala Shell query results in CSV

How can I save my query results in a CSV file via the Impala Shell.
My Code:
impala-shell -q "use test;
select * from teams;
-- From this point I need to save the query results to /Desktop (for example).
"
The problem that I am getting is that I have to select the DB first and then operate the query, but I only see syntax commands that directly uses the query instead of using the DB and then the query.
Found it.
impala-shell -B -o output.csv --output_delimiter=',' -q "use test;
select * from teams;"
You can use
impala-shell -B -q "select * from anylbi.tablename_1;" -o extract.csv
--print_header '--output_delimiter=,'
if you have a particular server you're trying to connect you can use the -i option and then the server name after impala-shell
eg:
Server : SERVER_NAME
Output File : output.csv
Database : test
Table name : teams
Delimiter : |
impala-shell -k -i SERVER_NAME --ssl -B -o output.csv --print_header --output_delimiter=| -q "use test; select * from teams";