Exchange Partition giving -Table or index is not partitioned. Invalid syntax - oracle

I have 2 schemas TBCAM and AR_TBCAM. There is a table called BKP_COST_EVENT in TBCAM which I have partitioned and I have moved the partition data into another simple table in AR_TBCAM schema called BKP_COST_EVENT_P2016. Now the data has moved to AR_TBCAM schema via this query
ALTER TABLE BKP_COST_EVENT EXCHANGE PARTITION P2016 WITH TABLE AR_TBCAM.BKP_COST_EVENT_P2016 INCLUDING INDEXES WITHOUT VALIDATION;
Now I want to bring the partition data back into the original table BKP_COST_EVENT.
But when I run this query standing on AR_TBCAM
ALTER TABLE BKP_COST_EVENT_P2016 EXCHANGE PARTITION P2016 WITH TABLE TBCAM.BKP_COST_EVENT INCLUDING INDEXES WITHOUT VALIDATION;
It is giving this error:
Error starting at line : 1 in command -
ALTER TABLE BKP_COST_EVENT_P2016 EXCHANGE PARTITION P2016 WITH TABLE TBCAM.BKP_COST_EVENT INCLUDING INDEXES WITHOUT VALIDATION
Error report -
ORA-14501: object is not partitioned
14501. 00000 - "object is not partitioned"
*Cause: Table or index is not partitioned. Invalid syntax.
*Action: Retry the command with correct syntax.
Can anyone suggest what am I doing wrong? Or how to bring/restore the data back to my TBCAM schema table BKP_COST_EVENT.
I have not dropped the partition p2016 in the original BKP_COST_EVENT

In exchange partition syntax first table should be the one which is partitioned, second should be unpartitioned one.
So, your first command was correct but 2nd command is wrong.
If you are bringing back data to same table's partition run the same command again.
ALTER TABLE BKP_COST_EVENT EXCHANGE PARTITION P2016 WITH TABLE AR_TBCAM.BKP_COST_EVENT_P2016 INCLUDING INDEXES WITHOUT VALIDATION;
Also, if there are no indexes to be moved, its better not to use including indexes clause.

Related

Hive External Table - Drop Partition

Facing a weird issue. Alter table command to drop partition works well for > or < or >= or <= signs but not for = check.
Working command:
ALTER TABLE XYZ DROP PARTITION(bizdate>'20231230');
Command that's not working and throwing an error stating that partition does not exist:
ALTER TABLE XYZ DROP PARTITION(bizdate='20231230');
When I do show partitions, I can see '20231230' partition.
Note: bizdate is a varchar(10)
Check the list of partition in the table:
SHOW PARTITIONS <table>;
Perhaps it tries dropping the partition. It seems that the data was removed at some point on HDFS but the hive tables metadata still thinks those partitions exist
ALTER TABLE *tableName* drop if exists PARTITION(bizdate="20231230");
& Re-pair the broken table
msck repair table *table_name*;

How to convert a partitioned table into a non-partitioned table by using Oracle online redefinition with the object id kept

It is not difficult to convert a partitioned table into a non-partitioned table if we use a Oracle online redefinition and the object id of the source table is changed as a result of the operation because the interim table (non-partitioned) becomes an original table.
I realized the following fact in Oracle redefinition:
To keep the object id of the source table, we should use an exchange partition of the redefinition, and its destination table is the same as the source table.
I wonder if there is any way to keep the object id in converting a partitioned table into a non-partitioned table with Oracle online redefinition.
The reason is that at times it is not allowed to change the object id in CDC(GoldenGate/SharePlex) environment.

How to delete fields from a partitioned table in Hive stored as parquet?

I'm looking for a way to modify a parquet data table in HIVE to remove some fields. The table is managed but it doesn't matter because I can convert it to external.
The problem is that I can not use the command ALTER TABLE ... REPLACE COLUMN with partitioned parquet tables.
It is works well for textfile format (partitioned or not) and only for non-partitioned parquet tables.
I've tried to replace column but this is the result:
hive> ALTER TABLE db_test.mytable REPLACE COLUMNS(name String);
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask.
Replacing columns cannot drop columns for table db_test.mytable.
SerDe may be incompatible
I've thought about some solutions, but none of them fits my scenario:
First
- [Optional] Convert the table in external.
- Delete the table.
- Re-create the table with the fields that I want.
- MSCK REPAIR TABLE to add HDFS partitions.
- [Optional] Convert back to managed table.
Second
- Create temporary table as selection of the original table with the fields that I choose.
- Delete the original table.
- Rename the temporary table to the original name.
Both options affect my process because I would lose the statistics of my table. This table is consumed with MicroStrategy by Impala and I need to mantain the statistics.
In addition, the second solution is bad with very large data tables.
Any suggestions?
Thanks in advance.
You can use first method and then run
hive> anayze table <db_name>.<table_name> compute statistics;
to compute all the statistics of the table.

Add PARTITION after creating TABLE in hive

i have created a non partitioned table and load data into the table,now i want to add a PARTITION on the basis of department into that table,can I do this?
If I do:
ALTER TABLE Student ADD PARTITION (dept='CSE') location '/test';
It gives me error:
FAILED: SemanticException table is not partitioned but partition spec exists: {dept=CSE}
please help. Thanks
First create a table in such a way so that you don't have partition column in the table.
create external table Student(col1 string, col2 string) partitioned by (dept string) location 'ANY_RANDOM_LOCATION';
Once you are done with the creation of the table then alter the table to add the
partition department wise like this :
alter table Student add partition(dept ='cse') location '/test';
I hope this will help.
You can't alter table partition if you didn't define partition while creation of table.
If, when altering a un-partitioned table to add partition, you get this error: "Semantic Exception table is not partitioned but partition spec exists: {dept=CSE}," it means you are trying to include the partitioned in the table itself.
You are not getting syntax error because the syntax of the command is correct and used to alter the partition column.
Learn more about Hive Tables:
https://www.dezyre.com//hadoop-tutorial/apache-hive-tutorial-tables
You can also check the possible alternation in table:
https://sites.google.com/site/hadoopandhive/home/how-to-create-table-partition-in-hive
Hope this helps.

Cant drop partition from header table

We have a header table which has a primary key and a detail table which references the header table (Foreign key). Both the header and detail tables are monthly partitioned. These tables contain 5 years of data, so when a new month comes the data for the first partition is deleted and so on. So that always only 5 years of data is maintained.
The problem that we are facing is while dropping the partition from the header we are getting the following error:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
ORA-06512: at "SCH_TEST.DROP_PARTITION", line 51
ORA-06512: at line 16 (DBD ERROR: OCIStmtExecute)
We have deleted the referencing data from the detail table, still the above error is occuring.
One way for solving this error is to disable the constraint, drop the partition and then enable the constraint. Is there any other approach/solution for this issue.
Database is Oracle 11G.
Edit 1: I'm able to drop the partition from header table if i delete the data in the partition first and then drop it. Any idea how this works?
Oracle 11g introduced partition by reference for this. Are you using reference partitioning? If not you need to change your partitioning scheme.
I chose "disable the reference constraint and then drop the partition" approach, as i did not find any other solution for this issue.
Posting this information here and accepting it as answer so that it may help others who search for the same issue.

Resources