[jvm-packages] remove the dep of com.fasterxml.jackson (#7791)
This commit is contained in:
parent
89d6419fd5
commit
729d227b89
@ -20,11 +20,6 @@
|
|||||||
<classifier>${cudf.classifier}</classifier>
|
<classifier>${cudf.classifier}</classifier>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<version>2.10.5.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.hadoop</groupId>
|
<groupId>org.apache.hadoop</groupId>
|
||||||
<artifactId>hadoop-hdfs</artifactId>
|
<artifactId>hadoop-hdfs</artifactId>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2021 by Contributors
|
Copyright (c) 2021-2022 by Contributors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -16,15 +16,7 @@
|
|||||||
|
|
||||||
package ml.dmlc.xgboost4j.gpu.java;
|
package ml.dmlc.xgboost4j.gpu.java;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.util.ArrayList;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cudf utilities to build cuda array interface against {@link CudfColumn}
|
* Cudf utilities to build cuda array interface against {@link CudfColumn}
|
||||||
@ -42,58 +34,64 @@ class CudfUtils {
|
|||||||
|
|
||||||
// Helper class to build array interface string
|
// Helper class to build array interface string
|
||||||
private static class Builder {
|
private static class Builder {
|
||||||
private JsonNodeFactory nodeFactory = new JsonNodeFactory(false);
|
private ArrayList<String> colArrayInterfaces = new ArrayList<String>();
|
||||||
private ArrayNode rootArrayNode = nodeFactory.arrayNode();
|
|
||||||
|
|
||||||
private Builder add(CudfColumn... columns) {
|
private Builder add(CudfColumn... columns) {
|
||||||
if (columns == null || columns.length <= 0) {
|
if (columns == null || columns.length <= 0) {
|
||||||
throw new IllegalArgumentException("At least one ColumnData is required.");
|
throw new IllegalArgumentException("At least one ColumnData is required.");
|
||||||
}
|
}
|
||||||
for (CudfColumn cd : columns) {
|
for (CudfColumn cd : columns) {
|
||||||
rootArrayNode.add(buildColumnObject(cd));
|
colArrayInterfaces.add(buildColumnObject(cd));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String build() {
|
private String build() {
|
||||||
try {
|
StringBuilder builder = new StringBuilder();
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
builder.append("[");
|
||||||
JsonGenerator jsonGen = new JsonFactory().createGenerator(bos);
|
for (int i = 0; i < colArrayInterfaces.size(); i++) {
|
||||||
new ObjectMapper().writeTree(jsonGen, rootArrayNode);
|
builder.append(colArrayInterfaces.get(i));
|
||||||
return bos.toString();
|
if (i != colArrayInterfaces.size() - 1) {
|
||||||
} catch (IOException ie) {
|
builder.append(",");
|
||||||
ie.printStackTrace();
|
}
|
||||||
throw new RuntimeException("Failed to build array interface. Error: " + ie);
|
|
||||||
}
|
}
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectNode buildColumnObject(CudfColumn column) {
|
/** build the whole column information including data and valid info */
|
||||||
|
private String buildColumnObject(CudfColumn column) {
|
||||||
if (column.getDataPtr() == 0) {
|
if (column.getDataPtr() == 0) {
|
||||||
throw new IllegalArgumentException("Empty column data is NOT accepted!");
|
throw new IllegalArgumentException("Empty column data is NOT accepted!");
|
||||||
}
|
}
|
||||||
if (column.getTypeStr() == null || column.getTypeStr().isEmpty()) {
|
if (column.getTypeStr() == null || column.getTypeStr().isEmpty()) {
|
||||||
throw new IllegalArgumentException("Empty type string is NOT accepted!");
|
throw new IllegalArgumentException("Empty type string is NOT accepted!");
|
||||||
}
|
}
|
||||||
ObjectNode colDataObj = buildMetaObject(column.getDataPtr(), column.getShape(),
|
|
||||||
column.getTypeStr());
|
|
||||||
|
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
String colData = buildMetaObject(column.getDataPtr(), column.getShape(),
|
||||||
|
column.getTypeStr());
|
||||||
|
builder.append("{");
|
||||||
|
builder.append(colData);
|
||||||
if (column.getValidPtr() != 0 && column.getNullCount() != 0) {
|
if (column.getValidPtr() != 0 && column.getNullCount() != 0) {
|
||||||
ObjectNode validObj = buildMetaObject(column.getValidPtr(), column.getShape(), "<t1");
|
String validString = buildMetaObject(column.getValidPtr(), column.getShape(), "<t1");
|
||||||
colDataObj.set("mask", validObj);
|
builder.append(",\"mask\":");
|
||||||
|
builder.append("{");
|
||||||
|
builder.append(validString);
|
||||||
|
builder.append("}");
|
||||||
}
|
}
|
||||||
return colDataObj;
|
builder.append("}");
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectNode buildMetaObject(long ptr, long shape, final String typeStr) {
|
/** build the base information of a column */
|
||||||
ObjectNode objNode = nodeFactory.objectNode();
|
private String buildMetaObject(long ptr, long shape, final String typeStr) {
|
||||||
ArrayNode shapeNode = objNode.putArray("shape");
|
StringBuilder builder = new StringBuilder();
|
||||||
shapeNode.add(shape);
|
builder.append("\"shape\":[" + shape + "],");
|
||||||
ArrayNode dataNode = objNode.putArray("data");
|
builder.append("\"data\":[" + ptr + "," + "false" + "],");
|
||||||
dataNode.add(ptr)
|
builder.append("\"typestr\":\"" + typeStr + "\",");
|
||||||
.add(false);
|
builder.append("\"version\":" + 1);
|
||||||
objNode.put("typestr", typeStr)
|
return builder.toString();
|
||||||
.put("version", 1);
|
|
||||||
return objNode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user