Registro del lenguaje Java e información sobre el tiempo de ejecución
Este ejemplo utiliza el siguiente nombre de archivo: ' TestJavaRuntime.java
Código
El código de este ejemplo explora funcionalidades que pueden no ser de uso común. El registro se puede utilizar para ayudar a rastrear la ejecución de un AE. Para que sea útil, el AE debe estar registrado con una máscara de registro y el registro debe estar habilitado a través de nzudxdbg. Para recibir mensajes de registro del sistema en la ventana donde se inició el sistema NPS, es necesario iniciar NPS con la opción '-i' ' (por ejemplo, 'nzstart -i'). Esto hace que los procesos NPS permanezcan unidos al terminal. La información de tiempo de ejecución proporciona estadísticas sobre el sistema NPS, incluyendo el número de dataslices, el número de SPUs y el locus de ejecución.
import org.netezza.ae.*;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class TestJavaRuntime {
private static final Executor exec =
Executors.newCachedThreadPool();
public static final void main(String [] args) {
try {
mainImpl(args);
} catch (Throwable t) {
System.err.println(t.toString());
NzaeUtil.logException(t, "main");
}
}
public static final void mainImpl(String [] args) {
NzaeApiGenerator helper = new NzaeApiGenerator();
while (true) {
final NzaeApi api = helper.getApi(NzaeApi.FUNCTION);
if (api.apiType == NzaeApi.FUNCTION) {
if (!helper.isRemote()) {
run(api.aeFunction);
break;
} else {
Runnable task = new Runnable() {
public void run() {
try {
TestJavaRuntime.run(api.aeFunction);
} finally {
api.aeFunction.close();
}
}
};
exec.execute(task);
}
}
}
helper.close();
}
public static void validateRuntime(Nzae aeFunc, long[] args, int type)
{
// argss:
// dataslice, transaction, hardware, numslices, numspus, locus
long dataslice = args[0];
long txid = args[1];
long hwid = args[2];
long nslices = args[3];
long nspus = args[4];
long locus = args[5];
NzaeRuntime aeRun = aeFunc.getRuntime();
String buf;
if (locus != aeRun.getLocus())
{
buf = "test fails: 1\n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (aeRun.getSuggestedMemoryLimit() != 123)
{
buf = "test fails: 7 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (aeRun.getUserQuery() == false)
{
buf ="test fails: 8 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (type != aeRun.getAdapterType())
{
buf = "test fails: 9 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (locus == NzaeRuntime.NZAE_LOCUS_POSTGRES) {
return;
}
if (dataslice != aeRun.getDataSliceId())
{
buf = "test fails: 2 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if ((txid != 0) && (txid != aeRun.getTransactionId()))
{
buf ="test fails: 3 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (hwid != aeRun.getHardwareId())
{
buf = "test fails: 4 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (nslices != aeRun.getNumberDataSlices())
{
buf = "test fails: 5 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
if (nspus != aeRun.getNumberSpus())
{
buf = "test fails: 6 \n";
aeFunc.log(Nzae.LOG_DEBUG, buf);
}
}
public static class MyHandler implements NzaeMessageHandler
{
public void evaluate(Nzae ae, NzaeRecord input, NzaeRecord output) {
final NzaeMetadata meta = ae.getMetadata();
long ar[] = new long[6];
for (int i=0; i < 6; i++)
{
Object o = input.getField(i);
NzaeFieldInfo fi = input.getFieldInfo(i);
if (fi.getNzType() == NzaeDataTypes.NZUDSUDX_INT64){
ar[i] = (Long)o;
}
else if (fi.getNzType() == NzaeDataTypes.NZUDSUDX_INT32){
ar[i] = (Integer)o;
}
}
validateRuntime(ae, ar, NzaeRuntime.NZAE_ADAPTER_UDTF);
String str = "done";
output.setField(0,str);
}
}
public static int run(Nzae ae)
{
ae.run(new MyHandler());
return 0;
}
}
Una compilación
Utilice la compilación estándar:
$NZ_EXPORT_DIR/ae/utilities/bin/compile_ae --language java --template compile \
TestJavaRuntime.java --version 3
Registro
Registra el ejemplo utilizando las opciones --mem y --mask. La opción --mask activa el registro para DEBUG y la opción --mem establece la información de tiempo de ejecución de memoria.
$NZ_EXPORT_DIR/ae/utilities/bin/register_ae \
--sig "runtimeae(int8,int8,int8,int8,int8,int8)" \
--return "table(val varchar(1000))" --class AeUdtf --language java \
--template udtf --version 3 --define "java_class=TestJavaRuntime" \
--mem 123 --mask debug
En ejecución
Antes de ejecutarlo, active el registro ejecutando nzudxdbg:
nzudxdbg
Processing 1 spus
.
done
Processing host
done
Ejecute la consulta en nzsql:
SELECT * FROM TABLE WITH FINAL(runtimeae(1,1,1,1,1,1));
VAL
------
done
(1 row)
El registro del sistema NPS aparece en la ventana donde se inició el sistema NPS:
04-16-10 12:27:27 (dbos.19600) [d,udx ] test fails: 2
04-16-10 12:27:27 (dbos.19600) [d,udx ] test fails: 3
04-16-10 12:27:27 (dbos.19600) [d,udx ] test fails: 4
Esta es la salida esperada, ya que los argumentos especificados no coincidían con el tiempo de ejecución en esos casos.