How to truncate or delete partition from db2 using bigsql? - hive

I have table in db2 (using bigsql) that is partitioned as per date on IBM BigInsights
table_name_abc
20150810
data corresponding to partition
20150811
data corresponding to partition
....
what I want is to delete particular partition say 20150810 or delete data from that partition
I tried this
db2 "truncate table test_schema.table_name_abc where partition_date = 20150810";
But it gave following error
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "where" was found following "test_table".
Expected tokens may include: "". SQLSTATE=42601
Can someone please instruct on how to do this?

Solved it by using the following command
db2 "ALTER TABLE test_schema.table_name_abc DROP PARTITION (partition_date = 20150515)";
Adding it as answer just in case someone needs it

Related

SQL (DB2) Creating table by selecting from other table

I´ve read several discussions and websites about creating a SQL query to create a table by selecting data from other table, but none of them solved my issue. I don´t know what else to do.
I am working on a SQL script to run a sequence of selects and creates do resume some data. I´ve been using this SQL queries on a SaS server using DB2 data. Now I need to migrate to Dbeaver to using other sources.
I just want to create a table by selecting some columns and data from other table, for this simple example :
"CREATE TABLE DB2XXXX.PaidResume AS
(SELECT HistoricalPaid.AccountNumber AS CONTA
FROM DB2XXX.HistPaid HistoricalPaid
WHERE HistoricalPaid.AccountNumber = 'XXXXX');
All I got it this error
Error occurred during SQL query execution
SQL Error [42601]: ILLEGAL SYMBOL "<END-OF-STATEMENT>". SOME SYMBOLS THAT MIGHT BE LEGAL ARE:. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.19.26
If I just exclude the "CREATE TABLE DB2XXXX.PaidResume AS" and run the select only, it works.
You must include WITH DATA or WITH NO DATA at the end of the SQL statement. For example:
create table u as (select a from t) with data;
See example at db<>fiddle.

Athena Query "mismatched input 'partition'" when trying to add partition

Here is my Athena Query. I am trying to add a partition to a table:
ALTER TABLE public_data_scraping_yahoo_finance_pricing_table
ADD PARTITION ("S3_DATE" = '2021-07')
LOCATION 's3://my-bucket/enriched_data/pricing/2021-07/';
I'm following the documentation as seen here. But I'm getting some sort of syntax error.
When I run it I get:
line 2:5: mismatched input 'partition'. expecting: '.', 'add' (service: amazonathena; status code: 400; error code: invalidrequestexception; request id: 8dd2f1ac-d197-4c4c-b2fc-024383fd30fb; proxy: null)
I have run other queries to add partitions before, and have never had this issue. I would expect this query to create the partition without any issues.
Is someone able to help me identify the issue?
Can you try to remove the quotes from the table name? This fixed this error for me when trying to remove partitions
Okay so it turns out the issue was because the partition field I was specifying was wrapped in double quotes "S3_DATE" when it shouldn't be.
So the correct query would be:
ALTER TABLE public_data_scraping_yahoo_finance_pricing_table
ADD PARTITION (S3_DATE='2021-07')
LOCATION 's3://my-bucket/enriched_data/pricing/2021-07/';

SKIP LOCKED DATA Syntax issue in DB2

I am trying to execute simple select query with SKIP LOCKED DATA
but getting syntax error. Below is the sample query
SELECT ELEMENT FROM WORKQUEUE
WHERE PRIORITY = '1' AND STATUS='OPEN'
SKIP LOCKED DATA;
Got error as below
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=SKIP;
<query_expression>;END-OF-STATEMENT, DRIVER=3.61.86
But as per documents it is valid query. Please let me know if I am doing something wrong?
I suspect you are not using Db2 for z/OS 10.0.0
I suspect you are using e.g Db2 11.1 and you need a manual page from that Db2 platform such as
"Evaluate uncommitted data through lock deferral" - https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0011218.html
because Db2 for Linux, Unix and Windows does not support the SKIP LOCKED DATA clause directly

Facing an error when trying to insert the data in database using db2?

I'm trying to insert a row in the table by using below code but it is throwing an error. can anyone help me out to solve the error?
Thanks in advance!!
db2 "Insert into TARIFF_PRODUCT_ATTRIBUTES values (409499, 'ADDITION_SMS_TEMPLATE', 'IDSSMS1')";
Error is :
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0204N "DB2EAI2.TARIFF_PRODUCT_ATTRIBUTES" is an undefined name.
SQLSTATE=42704
Common causes of SQL0204N in Db2:
spelling mistake in the object name
object does not exist in the currently connected Db2 database
object exists in current database but in a different schema than your current default schema (so you must qualify the name with the correct schema-name).
mixed case table name (Db2 will always uppercase unquoted object names, so if the object is Tariff_Product_Attributes then use double-quotes around the name in the SQL to allow Db2 to find the object).
There are other less common causes , see the documentation for the complete list.

exception with Hive long create table statement

I have a "very long" create external table" statement that i try to run in Hive (200+ columns) but I end up with this error message.
Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
It's suppose to create an external table over an already populated hbase table. If reduce the number of column in my Hive statement it works.
So could it be the max number of column?, a connection timeout? , the lenght of the statement?
Please share your thought.
Regards,
Breach
Not sure if the number of variables is the real problem given the limited information provided, but this post should be able to help you check if the number of variables is the problem.
Creating a hive table with ~40K columns
Change the type of column "PARAM_VALUE" in "SERDE_PARAMS" Table in metastore database.
Try this command if you are using mysql server for storing the metastore DB
ALTER TABLE SERDE_PARAMS MODIFY PARAM_VALUE TEXT NOT NULL;
Hope it works for you.