darold / ora2pg

Ora2Pg is a free tool used to migrate an Oracle database to a PostgreSQL compatible schema. It connects your Oracle database, scan it automatically and extracts its structure or data, it then generates SQL scripts that you can load into PostgreSQL.
http://www.ora2pg.com/
GNU General Public License v3.0
978 stars 341 forks source link

Fix incorrect "unsupported partition type" warning for oracle_fdw copy #1764

Closed nasmart closed 3 months ago

nasmart commented 3 months ago

Using Ora2Pg COPY with oracle_fdw on a partitioned table results in the following message:

WARNING: unsupported partition type on table '\<table name>'

Looking into the code I found that "WARNING: unsupported partition type" is only raised in the following block:

elsif ($self->{partition_by_reference} eq 'none')
                                {
                                        print STDERR "WARNING: unsupported partition type on table '$table'\n";
                                        $sql_output .=  " -- Unsupported partition type '" . $self->{partitions_list}{"\L$table\E"}{type} . "', please check constraint: " . $self->{partitions_list}{"\L$table\E"}{refconstraint} . "\n";
                                }

After some poking around I realised that the partition type is not defined at the point the oracle_fdw table is defined in the following:

my $fdw_definition = $self->export_table();

My initial attempt to resolve the false warning involved moving the above code to after the partitioning type has been obtained. That resulted in Ora2Pg attempting to create a foreign table with a "PARTITION BY" clause, which is not valid and therefore errors.

It seems the most appropriate approach is to disable the partitioning via disable_partition while populating fdw_definition and then set disable_partition back to its original value, so that's what I've implemented in the commit for this pull request.

I've run a range of tests in an attempt to validate that I've not broken something unexpected. However, my understanding of the code is very limited at this point so please review the approach and modify/reject the pull request as appropriate.

darold commented 3 months ago

Thanks!