分享

如何用C开发DataStage Parallel Routine

 dazheng 2008-05-20

    很多人都在问DataStage Parallel Routine如何写,可是几乎没有人回答,网上也没有找到。倒是从网上找到一个用C++开发Parallel Routine的 ,只是试了试没有成功。URL如下:http://blogs./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.olibTrxFuncs.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 DesignerTransformer中调用其即可


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多