All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.fastjson2.support.odps.JSONExtractInt32 Maven / Gradle / Ivy

There is a newer version: 2.0.53
Show newest version
package com.alibaba.fastjson2.support.odps;

import com.alibaba.fastjson2.JSONPath;
import com.alibaba.fastjson2.JSONReader;
import com.aliyun.odps.io.IntWritable;
import com.aliyun.odps.io.Text;
import com.aliyun.odps.udf.UDF;

import java.nio.charset.StandardCharsets;

public class JSONExtractInt32
        extends UDF {
    private final JSONPath path;
    private final IntWritable result = new IntWritable();

    public JSONExtractInt32(String path) {
        this.path = JSONPath.of(path);
    }

    public IntWritable eval(Text input) {
        JSONReader parser = JSONReader.of(input.getBytes(), 0, input.getLength(), StandardCharsets.UTF_8);
        int value = path.extractInt32Value(parser);
        if (parser.wasNull()) {
            return null;
        }
        result.set(value);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy