Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1946,22 +1946,33 @@ public IValueMeta customizeValueFromSqlType(
}

String typeName = rm.getColumnTypeName(index);
// Most dbs expose uuid as "UUID", sql server (native) as "UNIQUEIDENTIFIER"
if ("uuid".equalsIgnoreCase(typeName) || "uniqueidentifier".equalsIgnoreCase(typeName)) {
try {
if (typeName == null) {
return null;
}

int uuidTypeId = ValueMetaFactory.getIdForValueMeta("UUID");
typeName = typeName.toLowerCase();
try {
switch (typeName) {
// Most dbs expose uuid as "UUID", sql server (native) as "UNIQUEIDENTIFIER"
case "uniqueidentifier":
case "uuid":
{
int uuidTypeId = ValueMetaFactory.getIdForValueMeta("UUID");

// Keep any existing metadata
IValueMeta u = ValueMetaFactory.cloneValueMeta(v, uuidTypeId);
// Keep any existing metadata
IValueMeta u = ValueMetaFactory.cloneValueMeta(v, uuidTypeId);

u.setLength(-1);
u.setPrecision(-1);
u.setLength(-1);
u.setPrecision(-1);

return u;
} catch (HopPluginException ignore) {
// UUID plugin not present
return u;
}
case "json":
case "jsonb":
return ValueMetaFactory.cloneValueMeta(v, IValueMeta.TYPE_JSON);
}
} catch (HopPluginException ignore) {
// plugin not present
}
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/org/apache/hop/core/row/IValueMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,13 @@ static String getTypeDescription(int type) {
*/
boolean isNumeric();

/**
* Checks whether this Value is Json
*
* @return true if the value is Json
*/
boolean isJson();

/**
* Return the type of a value in a textual form: "String", "Number", "Integer", "Boolean", "Date",
* ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.apache.hop.core.row.IValueMeta;
import org.apache.hop.core.row.ValueDataUtil;
import org.apache.hop.core.util.EnvUtil;
import org.apache.hop.core.util.JsonUtil;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.xml.XmlHandler;
Expand Down Expand Up @@ -3242,6 +3243,12 @@ public boolean isBoolean() {
return type == TYPE_BOOLEAN;
}

@Override
@JsonIgnore
public boolean isJson() {
return type == TYPE_JSON;
}

/**
* Checks whether or not this value is of type Serializable
*
Expand Down Expand Up @@ -3533,9 +3540,7 @@ protected void writeJson(DataOutputStream outputStream, JsonNode jsonNode) throw
if (jsonNode == null) {
outputStream.writeInt(-1);
} else {
ObjectMapper objectMapper = new ObjectMapper();
String string = objectMapper.writeValueAsString(jsonNode);
byte[] chars = string.getBytes(StandardCharsets.UTF_8);
byte[] chars = JsonUtil.mapJsonToBytes(jsonNode);
outputStream.writeInt(chars.length);
outputStream.write(chars);
}
Expand Down Expand Up @@ -3575,8 +3580,7 @@ protected JsonNode readJson(DataInputStream inputStream) throws IOException {
byte[] chars = new byte[inputLength];
inputStream.readFully(chars);

ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readTree(chars, 0, inputLength);
return JsonUtil.jsonMapper().readTree(chars, 0, inputLength);
}

protected byte[] readBinaryString(DataInputStream inputStream) throws IOException {
Expand Down Expand Up @@ -4378,7 +4382,7 @@ public int compare(Object data1, Object data2) throws HopValueException {
}
}

private int typeCompare(Object data1, Object data2) throws HopValueException {
protected int typeCompare(Object data1, Object data2) throws HopValueException {
int cmp = 0;
switch (getType()) {
case TYPE_STRING:
Expand Down Expand Up @@ -5557,6 +5561,7 @@ public IValueMeta getValueFromSqlType(

IValueMeta newV = null;
try {
// JSON type is handled here because its type is 1111 (Object) when reading from SQL
newV = databaseMeta.getIDatabase().customizeValueFromSqlType(v, rm, index);
} catch (SQLException e) {
throw new SQLException(e);
Expand Down
Loading
Loading