Pivotal Knowledge Base

Follow

HowTo - Install PL/R on Pivotal Greenplum

Environment

Product Version
Pivotal Greenplum 4.3.x

Goal

This article will list the steps required to install a PL/R package on GPDB.

Download language extension or specific PL/R version for your database from link, for more information on how to use the site to download the product, check the link.  

Solution

Prerequisites:

  • Running GPDB database cluster
  • Database superuser access
  • GPDB PL/R package bundle (Package name indicates .gppkg extension, example "plr-ossv8.3.0.15_pv2.1_gpdb4.3orca-rhel5-x86_64.gppkg")


Background:

Greenplum database provides a utility named gppkg which is used to manage extensions on Greenplum database. It is available by default once Greenplum database has been installed.

PL/R package provides:

  • R language interpreter installation (rpm)
  • PL/R language extension (rpm)
  • Spec file (yml)
 
[gpadmin@mdw]$ gppkg ~/plr-ossv8.3.0.15_pv2.1_gpdb4.3orca-rhel5-x86_64.gppkg --list
...
... deps deps/R-3.1.0-1.x86_64.rpm gppkg_spec.yml plr-2.1-2.x86_64.rpm [gpadmin@mdw ]$

Let's go through the steps required to install PL/R package and execute R language.

  • Step 1: Login to Greenplum database master server as gpadmin (superuser) and install PL/R package.
 [gpadmin@hawq-mdw ~]$ gppkg -i /tmp/database/plr-1.0-rhel5-x86_64.gppkg
 20140304:16:22:25:009588 gppkg:hawq-mdw:gpadmin-[INFO]:-Starting gppkg with args: -i /tmp/database/plr-1.0-rhel5-x86_64.gppkg
 ..skipping..
 20140304:16:22:47:009588 gppkg:hawq-mdw:gpadmin-[INFO]:-Completed local installation of plr-1.0-rhel5-x86_64.gppkg.
 20140304:16:22:48:009588 gppkg:hawq-mdw:gpadmin-[INFO]:-Please source your $GPHOME/greenplum_path.sh file and restart the database.
 You can enable PL/R by running createlang plr -d mydatabase.
 20140304:16:22:48:009588 gppkg:hawq-mdw:gpadmin-[INFO]:-plr-1.0-rhel5-x86_64.gppkg successfully installed.
  • Step 2: Source greenplum_path.sh file to bring newly added environment variables related to R (R_HOME and LD_LIBRARY_PATH) 

Source greenplum path.

[gpadmin@hawq-mdw R-2.13.0]$ source /usr/local/greenplum-db/greenplum_path.sh 
  • Step 3: Restart the database
[gpadmin@hawq-mdw ~]$ gpstop -r 
  • Step 4: Create PLR language in the required database
[gpadmin@hawq-mdw R-2.13.0]$ createlang plr -d gpdb
[gpadmin@hawq-mdw R-2.13.0]$
  • Step 5: Verify by using a PL/R provided function:
gpdb=# CREATE OR REPLACE FUNCTION r_norm(n integer, mean float8, std_dev float8) RETURNS float8[ ] AS $$ x<-rnorm(n,mean,std_dev); return(x) $$ LANGUAGE 'plr';
CREATE FUNCTION

gpdb=# select r_norm(10, 0, 1);
r_norm

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------
{-0.594968297689264,0.594821586656143,-0.190296477302711,-1.47059675975334,1.12476617952888,-0.0872460122996645,-0.65897541817448,-0.225518786084194,-0.255592249303867,-0.37402
494336017}
(1 row)

gpdb=# CREATE TABLE test_norm_var AS SELECT id, r_norm(10,0,1) as x FROM (SELECT generate_series(1,30:: bigint) AS ID) foo DISTRIBUTED BY (id);
SELECT 30
  • Step 5: Configure R if necessary

You could need to make few modifications in Rscript file to use R langauge, else you can get an error like below:

[gpadmin@hawq-mdw bin]$/usr/local/greenplum-db/ext/R-2.13.0/bin/R
 WARNING: ignoring environment value of R_HOME
 ./R: line 227: /opt/releng/tools/R-Project/R/2.13.0/rhel5_x86_64/lib64/R/etc/ldpaths: No such file or directory

Workaround

Step 1: Edit R script

[gpadmin@hawq-mdw bin]$ vi /usr/local/greenplum-db/ext/R-2.13.0/bin/R

Step 2: Comment out existing R_HOME_DIR

#R_HOME_DIR=/opt/releng/tools/R-Project/R/2.13.0/rhel5_x86_64/lib64/R

Step 3: Add R_HOME_DIR variable point to greenplum installation location (It might differ based on your installation of HAWQ / Greeenplum, so change it appropriately)

export R_HOME_DIR=/usr/local/greenplum-db/ext/R-2.13.0/lib64/R

Miscellaneous

  • Pivotal internal employees reference: MPP-22802

Comments

  • Avatar
    George

    This is helpful.

  • Avatar
    ABDULRAWOOF KAMADOD

    Thanks this is helpful.

Powered by Zendesk