Skip to content

Commit 8506710

Browse files
Merge pull request #757 from oracle-devrel/witold_cloud
Witold cloud
2 parents 4482a5b + ab68177 commit 8506710

File tree

12 files changed

+371
-0
lines changed

12 files changed

+371
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# DBMS_CLOUD. API for accessing the data stored in the object storage
2+
3+
DBMS_CLOUD is a PL/SQL package, which allows for accessing the data stored in an object storage bucket. It supports not only Oracle Object Storage but also AWS S3 and Azure Blob. Can be used to read and write data stored outside of the database. To read the data we can create external tables or hybrid partitioned tables
4+
5+
Review Date: 24.01.2024
6+
7+
## Useful Links
8+
9+
### Documentation
10+
11+
- [Managing Hybrid Partitioned Tables](https://docs.oracle.com/en/database/oracle/oracle-database/19/vldbg/manage_hypt.html#GUID-ACBDB3B2-0A16-4CFD-8FF1-A57C9B3D907F)
12+
- [DBMS_CLOUD documentation](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_CLOUD.html#GUID-6CCC322D-26A9-47E7-8FF5-5FF23807C968)
13+
14+
15+
### Team Publications
16+
17+
- [Hybrid Partitioned Tables - an introduction with examples](https://blogs.oracle.com/coretec/post/hybrid-partitioned-tables-introduction)
18+
- [Hybrid Partitioned Tables and Lifecycle Management](https://blogs.oracle.com/coretec/post/hybrid-partitioned-tables-and-lifecycle-management)
19+
- [ORAWORLD magazine article page 26-31](https://www.oraworld.org/fileadmin/documents/27-ORAWORLD.pdf)
20+
21+
### Blogs
22+
23+
- [Oracle Autonomous Data Warehouse - Access Parquet Files in Object Stores](https://blogs.oracle.com/datawarehousing/post/oracle-autonomous-data-warehouse-access-parquet-files-in-object-stores)
24+
25+
### LiveLabs Workshops
26+
27+
- [Database 19c - Hybrid Partitioning](https://apexapps.oracle.com/pls/apex/dbpm/r/livelabs/view-workshop?wid=568)
28+
29+
# License
30+
31+
Copyright (c) 2023 Oracle and/or its affiliates.
32+
33+
Licensed under the Universal Permissive License (UPL), Version 1.0.
34+
35+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
-- this script
2+
-- (re)creates credentials
3+
-- (re)creates non-partitioned ORDERS and ORDER_ITEMS table
4+
-- loads data to above table from object storage by executing DBMS_CLOUD.COPY_DATA procedure
5+
-- creates external tables with exactly the same data
6+
7+
8+
alter session set nls_language=american;
9+
alter session set nls_territory=america;
10+
alter session set nls_date_format='YYYY-MM-DD';
11+
alter session set nls_timestamp_format='YYYY-MM-DD';
12+
13+
drop table orders cascade constraints;
14+
drop table order_items cascade constraints;
15+
16+
create table orders
17+
( ORDER_ID number(10),
18+
ORDER_DATE timestamp(9),
19+
ORDER_MODE varchar2(30),
20+
CUSTOMER_ID number(10),
21+
ORDER_STATUS number(10),
22+
ORDER_TOTAL number(10,2),
23+
SALES_REP_ID number(10),
24+
PROMOTION_ID number(10) );
25+
26+
create table order_items
27+
( ORDER_ID number(10),
28+
LINE_ITEM_ID number(10),
29+
PRODUCT_ID number(10),
30+
UNIT_PRICE number(10,2),
31+
QUANTITY number(10) );
32+
33+
begin
34+
dbms_credential.drop_credential(credential_name=>'DBMS_CLOUD_CREDENTIAL');
35+
end;
36+
/
37+
38+
begin
39+
dbms_credential.create_credential(credential_name=>'DBMS_CLOUD_CREDENTIAL',
40+
username=>'<tenancy_user_name>',
41+
password=>'<token>');
42+
end;
43+
/
44+
45+
select *
46+
from dbms_cloud.list_objects(
47+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
48+
location_uri => 'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/');
49+
50+
begin
51+
dbms_cloud.copy_data(
52+
table_name =>'ORDERS',
53+
credential_name =>'DBMS_CLOUD_CREDENTIAL',
54+
file_uri_list =>'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders.dat',
55+
format => json_object('ignoremissingcolumns' value 'true',
56+
'removequotes' value 'true',
57+
'skipheaders' value '1',
58+
'delimiter' value ';',
59+
'timestampformat' value 'YYYY-MM-DD')
60+
);
61+
end;
62+
/
63+
64+
begin
65+
dbms_cloud.copy_data(
66+
table_name =>'ORDER_ITEMS',
67+
credential_name =>'DBMS_CLOUD_CREDENTIAL',
68+
file_uri_list =>'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items.dat',
69+
format => json_object('ignoremissingcolumns' value 'true',
70+
'removequotes' value 'true',
71+
'skipheaders' value '1',
72+
'delimiter' value ';',
73+
'timestampformat' value 'YYYY-MM-DD')
74+
);
75+
end;
76+
/
77+
78+
drop table orders_ext;
79+
drop table order_items_ext;
80+
81+
begin
82+
dbms_cloud.create_external_table(
83+
table_name => 'ORDERS_EXT',
84+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
85+
file_uri_list => 'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders.dat',
86+
column_list => 'ORDER_ID number(10),
87+
ORDER_DATE timestamp(9),
88+
ORDER_MODE varchar2(30),
89+
CUSTOMER_ID number(10),
90+
ORDER_STATUS number(10),
91+
ORDER_TOTAL number(10,2),
92+
SALES_REP_ID number(10),
93+
PROMOTION_ID number(10)',
94+
format => json_object('ignoremissingcolumns' value 'true',
95+
'removequotes' value 'true',
96+
'skipheaders' value '1',
97+
'delimiter' value ';',
98+
'timestampformat' value 'YYYY-MM-DD')
99+
);
100+
end;
101+
/
102+
103+
begin
104+
dbms_cloud.validate_external_table('orders_ext');
105+
end;
106+
/
107+
108+
begin
109+
dbms_cloud.create_external_table(
110+
table_name => 'ORDER_ITEMS_EXT',
111+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
112+
file_uri_list => 'https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items.dat',
113+
column_list => 'ORDER_ID number(10),
114+
LINE_ITEM_ID number(10),
115+
PRODUCT_ID number(10),
116+
UNIT_PRICE number(10,2),
117+
QUANTITY number(10)',
118+
format => json_object('ignoremissingcolumns' value 'true',
119+
'removequotes' value 'true',
120+
'skipheaders' value '1',
121+
'delimiter' value ';',
122+
'timestampformat' value 'YYYY-MM-DD')
123+
);
124+
end;
125+
/
126+
127+
begin
128+
dbms_cloud.validate_external_table('order_items_ext');
129+
end;
130+
/
131+
132+
set timing on
133+
134+
prompt "calculating number of rows in ORDERS table"
135+
select count(*) from orders;
136+
137+
prompt "calculating number of rows in ORDERS_EXT table"
138+
select count(*) from orders_ext;
139+
140+
prompt "calculating number of rows in ORDER_ITEMS table"
141+
select count(*) from order_items;
142+
143+
prompt "calculating number of rows in ORDER_ITEMS_EXT table"
144+
select count(*) from order_items_ext;
145+
146+
set timing off
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
-- this script
2+
-- (re)creates partitioned versions of ORDERS and ORDER_ITEMS tables
3+
-- (re)creates hybrid partitioned versions of ORDERS and ORDER_ITEMS tables
4+
-- loads data to both sets of tables using tables created in lab01.sql
5+
-- compares the performance of queries executed on internal and hybrid partitioned tables
6+
7+
alter session set nls_language=american;
8+
alter session set nls_territory=america;
9+
alter session set nls_date_format='YYYY-MM-DD';
10+
alter session set nls_timestamp_format='YYYY-MM-DD';
11+
12+
drop table orders_part cascade constraints;
13+
drop table order_items_part cascade constraints;
14+
15+
create table orders_part
16+
partition by range(order_id)
17+
( partition o_p01 values less than (250000),
18+
partition o_p02 values less than (500000),
19+
partition o_p03 values less than (750000),
20+
partition o_p04 values less than (1000000),
21+
partition o_p05 values less than (1250000),
22+
partition o_p06 values less than (1500000),
23+
partition o_p07 values less than (1750000),
24+
partition o_p08 values less than (maxvalue))
25+
as select * from orders;
26+
27+
create table order_items_part
28+
partition by range(order_id)
29+
( partition oi_p01 values less than (250000),
30+
partition oi_p02 values less than (500000),
31+
partition oi_p03 values less than (750000),
32+
partition oi_p04 values less than (1000000),
33+
partition oi_p05 values less than (1250000),
34+
partition oi_p06 values less than (1500000),
35+
partition oi_p07 values less than (1750000),
36+
partition oi_p08 values less than (maxvalue))
37+
as select * from order_items;
38+
39+
drop table orders_hpart cascade constraints;
40+
drop table order_items_hpart cascade constraints;
41+
42+
begin
43+
dbms_cloud.create_hybrid_part_table(
44+
table_name => 'ORDERS_HPART',
45+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
46+
format => json_object('ignoremissingcolumns' value 'true',
47+
'removequotes' value 'true',
48+
'skipheaders' value '1',
49+
'delimiter' value ';',
50+
'timestampformat' value 'YYYY-MM-DD'),
51+
column_list => 'ORDER_ID number(10),
52+
ORDER_DATE timestamp(9),
53+
ORDER_MODE varchar2(30),
54+
CUSTOMER_ID number(10),
55+
ORDER_STATUS number(10),
56+
ORDER_TOTAL number(10,2),
57+
SALES_REP_ID number(10),
58+
PROMOTION_ID number(10)',
59+
partitioning_clause => 'partition by range (order_id) (
60+
partition o_hp01 values less than (250000),
61+
partition o_hp02 values less than (500000),
62+
partition o_hp03 values less than (750000),
63+
partition o_hp04 values less than (1000000),
64+
partition o_hp05 values less than (1250000),
65+
partition o_hp06 values less than (1500000),
66+
partition o_hp07 values less than (1750000) external location (
67+
''https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders_p07.dat''),
68+
partition o_hp08 values less than (maxvalue) external location (
69+
''https://https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/orders_p08.dat'')
70+
)'
71+
);
72+
end;
73+
/
74+
75+
begin
76+
dbms_cloud.validate_external_table('orders_hpart');
77+
end;
78+
/
79+
80+
begin
81+
dbms_cloud.create_hybrid_part_table(
82+
table_name => 'order_items_hpart',
83+
credential_name => 'DBMS_CLOUD_CREDENTIAL',
84+
format => json_object('ignoremissingcolumns' value 'true',
85+
'removequotes' value 'true',
86+
'skipheaders' value '1',
87+
'delimiter' value ';'),
88+
column_list => 'ORDER_ID number(10),
89+
LINE_ITEM_ID number(10),
90+
PRODUCT_ID number(10),
91+
UNIT_PRICE number(10,2),
92+
QUANTITY number(10)',
93+
partitioning_clause => 'partition by range (order_id) (
94+
partition oi_hp01 values less than (250000),
95+
partition oi_hp02 values less than (500000),
96+
partition oi_hp03 values less than (750000),
97+
partition oi_hp04 values less than (1000000),
98+
partition oi_hp05 values less than (1250000),
99+
partition oi_hp06 values less than (1500000),
100+
partition oi_hp07 values less than (1750000) external location (
101+
''https://https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items_p07.dat''),
102+
partition oi_hp08 values less than (maxvalue) external location (
103+
''https://https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/order_items_p08.dat'')
104+
)'
105+
);
106+
end;
107+
/
108+
109+
begin
110+
dbms_cloud.validate_external_table('order_items_hpart');
111+
end;
112+
/
113+
114+
insert into orders_hpart
115+
select *
116+
from ORDERS
117+
where order_id < 1500000;
118+
119+
insert into order_items_hpart
120+
select *
121+
from ORDER_ITEMS
122+
where order_id < 1500000;
123+
124+
commit;
125+
126+
set timing on
127+
128+
prompt "calculating number of rows in ORDERS_PART table"
129+
select count(*) from orders_part;
130+
131+
prompt "calculating number of rows in ORDERS_HPART table"
132+
select count(*) from orders_hpart;
133+
134+
prompt "calculating number of rows in ORDER_ITEMS_PART table"
135+
select count(*) from order_items_part;
136+
137+
prompt "calculating number of rows in ORDER_ITEMS_HPART table"
138+
select count(*) from order_items_HPART;
139+
140+
set timing off
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- this script
2+
-- presents differences in execution plans end statistisc for
3+
-- queries reading data from internal and external tables
4+
5+
alter session set nls_language=american;
6+
alter session set nls_territory=america;
7+
alter session set nls_date_format='YYYY-MM-DD';
8+
alter session set nls_timestamp_format='YYYY-MM-DD';
9+
10+
set autotrace on
11+
12+
select count(*)
13+
from ORDERS;
14+
15+
select count(*)
16+
from ORDERS_EXT;
17+
18+
select count(*)
19+
from ORDER_ITEMS;
20+
21+
select count(*)
22+
from ORDER_ITEMS_EXT;
23+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- this script
2+
-- presents differences in execution plans end statistisc for
3+
-- queries reading data from internal and external partitions
4+
5+
alter session set nls_language=american;
6+
alter session set nls_territory=america;
7+
alter session set nls_date_format='YYYY-MM-DD';
8+
alter session set nls_timestamp_format='YYYY-MM-DD';
9+
10+
set autotrace on
11+
12+
select count(*)
13+
from ORDERS_HPART
14+
where order_id < 1500000;
15+
16+
select count(*)
17+
from ORDERS_HPART
18+
where order_id >= 1500000;
19+
20+
select count(*)
21+
from ORDER_ITEMS_HPART
22+
where order_id < 1500000;
23+
24+
select count(*)
25+
from ORDER_ITEMS_HPART
26+
where order_id >= 1500000;
27+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)