PX 转换例程编译问题

PX Transform Routine compile issues

本文关键字:问题 编译 例程 转换 PX      更新时间:2023-10-16

>我有一个用 C++ 编写的转换器例程,该例程设置为清除所有空格并在输入字符串为 null 或空时映射到一个值。c ++代码已编译并已正确测试,但是我在使例程在Datastage中工作时遇到问题。

根据说明,我已经复制了我在DS环境中的确切编译器选项,如下所示。

g++ -c -O -fPIC -Wno-deprecated -m64 -mtune=generic -mcmodel=small BlankToValue.cpp
g++ -shared -m64 BlankToValue.so BlankToValue.o

但是,在作业中测试例程时,我收到以下错误。

Sequential_File_36,0: 内部错误: (shbuf(: IOMGR/IOMGRC: 2649

我应该使用一组不同的选项进行编译吗?

作为参考,请参阅 c++ 代码。

#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <locale.h>
#include <locale>
char * BlankToValue(char *InStr, char *RepStr)
{
if (InStr[0] == '')                           // Check for null pointer at first character of input string.
{
return RepStr;                              // Return replacement string if true. This is to prevent unnecessary processing.
} else
{
const char* checkstr = InStr;               // Establish copy of inputstring stored in checkstring.
do {                                        // Start outer loop.
while (isspace(*checkstr)) {            // Inner loop while current checkstring byte is whitespace.
++checkstr;                         // Increment to next checkstring byte.
}
} while ((*InStr++ = *checkstr++));         // Set inputstring byte to current checkstring and iterate both. Breaks when either string evaluates to null.
*InStr = '';                              // Set null terminator for input string at current byte location.
if (InStr[0] == '')                       // Checks first character of cleaned input string for null pointer.
{
return RepStr;                          // Return replacement string if true.
} else
{
return InStr;                           // Return new input string if false.
}
}
}

威廉,

在指向此自定义函数的 DataStage 例程定义中,您是选择例程类型作为对象(在作业运行时编译到转换器阶段的 .o 文件(还是库(在作业运行时加载但对库命名约定有要求的 lib.so 文件,并且该库位于库路径中(。 上面的代码建议您正在创建一个 *.so 文件,但没有以 lib 为前缀。 下面是一个示例: https://www.ibm.com/support/pages/node/403041

此外,如果作业日志中的第一个错误不是库加载错误,而是内部错误 (shbuf( 错误,我发现过去使用自定义例程会发生过几种情况:

自定义例程
  1. 涉及空处理,您的例程也是如此,并且在升级到 Information Server 8.5 后,当我们的产品中的空处理规则发生更改时,自定义例程开始失败。 这些更改解释如下: https://www.ibm.com/support/pages/node/433863 您可以通过使用新的作业级别环境变量运行作业来测试这是否是问题所在:APT_TRANSFORM_COMPILE_OLD_NULL_HANDLING=1

  2. 在另一种情况下,自定义例程中的 shbuf 错误是转换器级接收到大记录(大于自定义例程中定义的数据类型可以处理的记录(的结果。 在所有字符串类型字段中仅使用具有较小值的单个示例输入记录时,作业是否仍然失败。

谢谢。

另外,我注意到错误来自顺序文件阶段,而不是使用自定义例程的转换器阶段。 因此,可能还需要考虑自定义例程的输出数据类型是什么,并确保它以有效值退出,该值对于数据类型来说不会太大,也不会大于阶段之间使用的默认传输缓冲区大小(默认为 128k(。

经过一两天多次尝试不同的编译和代码方法,我找到了解决问题的方法。下面的代码在传递空列时抛出分段错误。回想起来,这是有道理的。

if (InStr[0] == '')

它已被更正到下面,现在一切正常。

if ((InStr == NULL) || (InStr[0] == ''))