如何用C开发DataStage Parallel Routine

写于2008年春, datastage6.5

很多人都在问DataStage Parallel Routine如何写,可是几乎没有人回答,网上也没有找到。倒是从网上找到一个用C++开发Parallel Routine的 ,只是试了试没有成功。URL如下:http://blogs.ittoolbox.com/dw/soa/archives/datastage-parallel-routines-made-really-easy-20926

我用DataStage自带的示例做了一下,server端为AIX环境,供大家参考

1、用C开发Parallel Routine,需要用到 Makefile去编译C文件
创建C文件和Makefile文件,

C文件如下:

**

/*
//
// Example functions to be used as parallel external user functions in the transformer stage
//
// These are examples for Solaris, and are intended for demonstration purposes only.
//
*/
#include "string.h"
/*
// Case 1: Returning an int value
*/
int TrxFuncInt()
{
    return -1034;
}
/*
// Case 2: Returning an unsigned char
*/
unsigned char TrxFuncUChar()
{
    return (unsigned char)‘&‘;
}
/*
// Case 3: Returning a long
*/
long long TrxFuncLong()
{
    return 119921;
}
/*
// Case 4: Returning a char string
*/
char* TrxFuncCharStr()
{
    return (char*)"TestString";
}
/*
// Case 5: A function taking one of each type of argument
*/
int TrxFuncAllArgs(signed char arg1, unsigned char arg2,
                    short arg3,       unsigned short arg4,
                    int arg5,         unsigned int arg6,
                    long long arg7,   unsigned long long arg8,
                    float arg9,
                    double arg10,
                    char* arg11)
{
    int retval;
    /*
    // this just checks the value of each input argument. If all the values are
    // as expected then it returns 0, otherwise -1
    */
    if (arg1 != ‘&‘) {
        retval = -1;
    } else if (arg2 != (unsigned char)‘&‘) {
        retval = -1;
    } else if (arg3 != -3) {
        retval = -1;
    } else if (arg4 != 4) {
        retval = -1;
    } else if (arg5 != 5555) {
        retval = -1;
    } else if (arg6 != 6665) {
        retval = -1;
    } else if (arg7 != -77777) {
        retval = -1;
    } else if (arg8 != 87654) {
        retval = -1;
    } else if ((arg9 <= 2.2) || (arg9 >= 2.4)) {
        retval = -1;
    } else if (arg10 != 4.3) {
        retval = -1;
    } else if (strcmp(arg11, (char*)"TestString") != 0) {
        retval = -1;
    } else {
        retval = 0;
    }
    return retval;
}

**

Makefile文件内容如下:

# =====================================================================

# Example Makefile to build the example transformer external functions

#

# SOLARIS version, intended for demonstration purposes only.

#

# =====================================================================

TARGETLIB   = libTrxFuncs.so

CODESRC         = TrxFuncs.c

TARGETOBJ  = TrxFuncs.o

CC          = g++

CCOPTIONS   = -O -fPIC

LIBCC       = $(CC)

LDOPTIONS   = -nostartfiles -Wl,-Bshareable,-Bsymbolic,--allow-shlib-undefined

.SUFFIXES: .c .o

# ---------------------------------------------------------------------

# Rules

# ---------------------------------------------------------------------

all: $(TARGETLIB)

$(TARGETLIB):     $(TARGETOBJ)

       $(LIBCC) $(LDOPTIONS) $(TARGETOBJ) -o $(TARGETLIB)

$(TARGETOBJ): $(CODESRC)

       $(CC) $(CCOPTIONS) -c $(CODESRC) -o $(TARGETOBJ)

clean:

       @rm -f $(TARGETOBJ) $(TARGETLIB)

# ---------------------------------------------------------------------

# End of makefile

# ---------------------------------------------------------------------

2、 将这两个文件放在DataStage 服务器下,然后执行:make;这样会生成TrxFuncs.o和libTrxFuncs.so文件
3、 在DataStage Manager下创建一个Parallel Routine
Routine name写Routine的名字,External subroutine name则写.c文件中的function名称。如果在Object type中选择Library, 则在Library path中写libTrxFuncs.so文件;如果是选择Object,则在Library path中写TrxFuncs.o文件。然后保存退出
4、然后在DataStage Designer的Transformer中调用其即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值