After you install the formats
that SAS supplies in libraries inside the Greenplum data warehouse
and publish any custom format definitions that you created in SAS,
you can access the SAS_PUT( ) function with your SQL queries.
If the SQLMAPPUTTO=
system option is set to SAS_PUT and you submit your program from a
SAS session, the SAS SQL processor maps PUT function calls to SAS_PUT( )
function references that Greenplum understands.
This example illustrates
how the PUT function is mapped to the SAS_PUT( ) function using
implicit pass-through.
/* implicit pass-thru query */
options sqlgeneration=dbms sqlreduceput=none;
options sastrace=',,,d' sastraceloc=saslog
sql_ip_trace=(note,source) msglevel=i;
proc sql noerrorstop reduceput=none details="reduce_put_bench$";
create table fmt_ipout as
select distinct id, put(a,ANIMAL.) len=50 as fmtresult
from dblib.sample ;
quit;
options sastrace=',,,,'
sql_ip_trace=none msglevel=n;
This is a partial listing
of the lines that are written to the SAS log.
/*
GREENPL_1: Prepared:
SELECT * FROM SAMPLE FOR READ ONLY
NOTE: XOG: Put Ping Query
NOTE: SELECT SAS_PUT('ANIMAL', '$IS-INTRINSIC') AS X, SAS_PUT('ANIMAL',
'$FMT-META') AS Y FROM (SELECT COUNT(*) AS C FROM SAMPLE WHERE 0=1)
GREENPL_2: Prepared:
select distinct TXT_1."id", cast(SAS_PUT(TXT_1."a", 'ANIMAL20.0') as char(20))
as fmtresult from SAMPLE TXT_1
SQL_IP_TRACE: pushdown attempt # 1
SQL_IP_TRACE: passed down query:
select distinct TXT_1."id", cast(SAS_PUT(TXT_1."a", 'ANIMAL20.0') as char(20))
as fmtresult from SAMPLE TXT_1
SQL_IP_TRACE: The SELECT statement was passed to the DBMS.
GREENPL_3: Executed:
Prepared statement GREENPL_2
ACCESS ENGINE: SQL statement was passed to the DBMS for fetching data.
*/
Be aware of these items:
-
The SQLMAPPUTTO= system option
must be set to SAS_PUT to ensure that the SQL processor maps your
PUT functions to the SAS_PUT( ) function and the SAS_PUT( )
reference is passed through to Greenplum.
-
The SAS SQL processor translates
the PUT function in the SQL SELECT statement into a reference to the
SAS_PUT( ) function.
select distinct TXT_1."id",
cast(SAS_PUT(TXT_1."a", 'ANIMAL20.0') as char(20)) as fmtresult
from SAMPLE TXT_1
A large value, VARCHAR(
n),
is always returned because one function prototype accesses all formats.
Use the CAST expression to reduce the width of the returned column
to be a character width that is reasonable for the format that is
being used.
The return text cannot
contain a binary zero value (hexadecimal 00) because the SAS_PUT( )
function always returns a VARCHAR(
n)
data type and a Greenplum VARCHAR(
n)
is defined to be a null-terminated string.
The SELECT DISTINCT
clause executes inside Greenplum, and the processing is distributed
across all available data nodes. Greenplum formats the
id
values
with the ANIMAL 20.0 format and processes the SELECT DISTINCT clause
using the formatted values.