BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nagayamini
Calcite | Level 5

Hello,

 

In my current project, we have a requirement to load SAS datasets into HDFS using SAS access to Hadoop.

In this, we are supposed to create external partitions (as we have in HIVEQL) using SAS access.

 

Please help me with the options if any to create external partitions and during a reload we are supposed to drop those partitions as well.

I have seen that we can use DB_CREATE_TABLE_OPTS and use an existing partition but my requirement is to add an external partition which is not existing already in the table.

 

Please let me know if any other details are required.

Quick response would be highly appreciated.

 

Best Regards

Yamini

1 ACCEPTED SOLUTION

Accepted Solutions
JBailey
Barite | Level 11

Hi @nagayamini

 

You may find the following HiveQL statements helpful:

 

 

ALTER TABLE myschema.table1 ADD IF NOT EXISTS PARTITION (mydate='2018-07-04') 
LOCATION 'hdfs://some/hdfs/filesystem/months/mydate=2018-07-04' ALTER TABLE myschema.table1 DROP PARTITION (mydate='2018-07-04');

These statements can be placed in SAS EXECUTE(...) BY HADOOP statements.

 

Update - example EXECUTE statements...

LIBNAME myHDP HADOOP ... some valid LIBNAME statement;

PROC SQL;
CONNECT USING myHDP;
EXECUTE(ALTER TABLE myschema.table1 ADD IF NOT EXISTS PARTITION (mydate='2018-07-04') 
   LOCATION 'hdfs://some/hdfs/filesystem/months/mydate=2018-07-04') BY myHDP;

EXECUTE(ALTER TABLE myschema.table1 DROP PARTITION 
 (mydate='2018-07-04') ) BY myHDP;
QUIT;

 

Best wishes,
Jeff

View solution in original post

8 REPLIES 8
JBailey
Barite | Level 11

Hi @nagayamini

 

You may find the following HiveQL statements helpful:

 

 

ALTER TABLE myschema.table1 ADD IF NOT EXISTS PARTITION (mydate='2018-07-04') 
LOCATION 'hdfs://some/hdfs/filesystem/months/mydate=2018-07-04' ALTER TABLE myschema.table1 DROP PARTITION (mydate='2018-07-04');

These statements can be placed in SAS EXECUTE(...) BY HADOOP statements.

 

Update - example EXECUTE statements...

LIBNAME myHDP HADOOP ... some valid LIBNAME statement;

PROC SQL;
CONNECT USING myHDP;
EXECUTE(ALTER TABLE myschema.table1 ADD IF NOT EXISTS PARTITION (mydate='2018-07-04') 
   LOCATION 'hdfs://some/hdfs/filesystem/months/mydate=2018-07-04') BY myHDP;

EXECUTE(ALTER TABLE myschema.table1 DROP PARTITION 
 (mydate='2018-07-04') ) BY myHDP;
QUIT;

 

Best wishes,
Jeff

nagayamini
Calcite | Level 5

Thanks for the solution Jeff, but I can see that merge and alter statements are not supported in SAS Execute as per below link.

I even tried using merge syntax of HIVE in this execute statement but it is giving an error.

 

Can you please advise other alternative for this scenario.

 

http://support.sas.com/documentation/cdl/en/acreldb/63647/HTML/default/viewer.htm#execute.html

JBailey
Barite | Level 11

Hi @nagayamini

 

I have updated my response. Your link is bad...

 

Best wishes, 

Jeff

 

nagayamini
Calcite | Level 5

Thank you Jeff, it worked. 

 

 

JBailey
Barite | Level 11

HI @nagayamini

 

My pleasure!

 

Best wishes,

Jeff

ChrisNZ
Tourmaline | Level 20

Do you want dynamic or static partitions?

 

If the table is created with option PARTITIONED BY it will be partitioned.

 

You can then add dynamic partitions with something like:

ALTER TABLE test ADD PARTITION (dt='2014-03-05')

 

and you can insert data with:

INSERT INTO TABLE test PARTITION(dt='2014-03-05') SELECT a,b,c,d from table

 

 

nagayamini
Calcite | Level 5

Hi Chriz,

I would like to add dynamic partitions using SAS Access to Hadoop interface in which I can't directly use alter command which you mentioned.

 

As stated by Jeff, need to use execute in order to use DBMS specific queries.

ChrisNZ
Tourmaline | Level 20

need to use execute in order to use DBMS specific queries. I can't directly use alter command which you mentioned.

Of course you can.

 

libname HAD001 hadoop ... ;

proc sql;

  connect using HAD001;

  execute by HAD001 ( alter table ...  ) ;

 

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2985 views
  • 0 likes
  • 3 in conversation