count function doesn't work in hiveql - hiveql

hello friends i have written a hive query to get the count number as a variable. I will use this variable to update a column. But this query doesn't function well. It always give a Syntax error: ")" unexpected. Can anybody help me regarding this error? Here is my query-
select count(tank_items_id) AS count_tank_items
from master_data_assortment.tank_items_actual
where item_type = 'shop_offer';
Thank you.
Regards
Mirish

try running as hive -e "select count(tank_items_id) AS count_tank_items from master_data_assortment.tank_items_actual where item_type = 'shop_offer';"
you should run in hive prompt not in cli

Related

Sequelize how to use aggregate function on Postgres JSONB column

I have created one table with JSONB column as "data"
And the sample value of that column is
[{field_id:1, value:10},{field_id:2, value:"some string"}]
Now there are multiple rows like this..
What i want ?
I want to use aggregate function on "data" column such that, i should
get
Sum of all value where field_id = 1;
Avg of value where field_id = 1;
I have searched alot on google but not able to find a proper solution.
sometimes it says "Field doesn't exist" and some times it says "from clause missing"
I tried referring like data.value & also data -> value lastly data ->> value
But nothing is working.
Please let me know the solution if any one knows,
Thanks in advance.
Your attributes should be something like this, so you instruct it to run the function on a specific value:
attributes: [
[sequelize.fn('sum', sequelize.literal("data->>'value'")), 'json_sum'],
[sequelize.fn('avg', sequelize.literal("data->>'value'")), 'json_avg']
]
Then in WHERE, you reference field_id in a similar way, using literal():
where: sequelize.literal("data->>'field_id' = 1")
Your example also included a string for the value of "value" which of course won't work. But if the basic Sequelize setup works on a good set of data, you can enhance the WHERE clause to test for numeric "value" data, there are good examples here: Postgres query to check a string is a number
Hopefully this gets you close. In my experience with Sequelize + Postgres, it helps to run the program in such a way that you see what queries it creates, like in a terminal where the output is streaming. On the way to a working statement, you'll either create objects which Sequelize doesn't like, or Sequelize will create bad queries which Postgres doesn't like. If the query looks close, take it into pgAdmin for further work, then try to reproduce your adjustments in Sequelize. Good luck!

Spark sql group by and sum changing column name?

In this data frame I am finding total salary from each group. In Oracle I'd use this code
select job_id,sum(salary) as "Total" from hr.employees group by job_id;
In Spark SQL tried the same, I am facing two issues
empData.groupBy($"job_id").sum("salary").alias("Total").show()
The alias total is not displaying instead it is showing "sum(salary)" column
I could not use $ (I think Scala SQL syntax). Getting compilation issue
empData.groupBy($"job_id").sum($"salary").alias("Total").show()
Any idea?
Use Aggregate function .agg() if you want to provide alias name. This accepts scala syntax ($" ")
empData.groupBy($"job_id").agg(sum($"salary") as "Total").show()
If you dont want to use .agg(), alias name can be also be provided using .select():
empData.groupBy($"job_id").sum("salary").select($"job_id", $"sum(salary)".alias("Total")).show()

In orientdb what is difference between in('edge_type') and in(edge_type)

Trying this query in Grateful dead database provided in orientdb gives 146 records:
select expand(in('sung_by')) from V where name = 'Garcia'
But when we try the similar version of below query: select expand(in(sung_by)) from V where name = 'Garcia', 150 records are returned
Is it a bug?? Just trying orientdb from past week, followed tutorial from this website and this was second issue found.
By using select expand(in(sung_by)), the value of the field sung_by is resolved at query execution, but there is no field called sung_by, so it's null.
For this reason, it's like executing select expand(in()) in that case. By using 'sung_by', instead, only the edges with label sung_by will be traversed.
So, put always " or ' around edge's class/label to traverse.

In Talend how to give the tfilerowcount value to input of the MySQL query?

I'm a beginner to Talend. I have stopped at one point in my requirement.
My requirement is I have to pass the filecount value to MySQL query on LIMIT Clause. Ex: if I can get file count from tfilerowcount item in talend. Once received this value, I have to pass it to tMysqlInput query as
select * from table_name limit "+tFileRowCount_1.filecount+";
You can get the number of rows in a file using below
(Integer)globalMap.get("tFileRowCount_1_COUNT")
Hope this would help you out.

Executing the query using bq command line in Google Big Query

I execute a query using the below Python script and the table gets populated with 2,564,691 rows. When I run the same query using Google Big Query console, it returns 17,379,353 rows (query is as-is). I was wondering whether there is some issue with the below script. Not sure whether --replace in bq query replaces the past result set instead of appending to it.
Any help would be appreciated.
dateToday = (time.strftime("%Y/%m/%d"))
dateToday1 = dateToday.replace('/','')
commandStr = "type C:\Users\query.txt | bq query --allow_large_results --replace --destination_table table:dataset1_%s -n 1" %(dateToday1)
In the Web UI you can use Query History option to navigate to respective queries.
After you locate them - you can expand respective entries and see what exactly query was executed
I am more than sure that just comparing query texts you will see source of "discrepancy" right away!
added
In Query History - not only you can see Query Text, but also all configuration properties that were used for respective query - like Write Preference for example and others. So even if query text the same you can see potential difference in configuration that will give you a clue