Skip to content

Commit

Permalink
SNOW-956803 - Mapping of structured type fields description
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki committed Jan 3, 2024
1 parent df8c4ec commit ff12158
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 80 deletions.
167 changes: 167 additions & 0 deletions src/main/java/net/snowflake/client/core/JsonSQLOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package net.snowflake.client.core;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Date;
import java.util.*;

public class JsonSQLOutput implements SQLOutput {

private Vector attribs = new Vector();
private Map map = new HashMap();
private final ObjectMapper OBJECT_MAPPER = ObjectMapperFactory.getObjectMapper();

public String getJsonString() {
try {
return OBJECT_MAPPER.writeValueAsString(attribs);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

@Override
public void writeString(String value) throws SQLException {
attribs.add(value);
}

@Override
public void writeBoolean(boolean x) throws SQLException {

}

@Override
public void writeByte(byte x) throws SQLException {

}

@Override
public void writeShort(short x) throws SQLException {

}

@Override
public void writeInt(int x) throws SQLException {

}

@Override
public void writeLong(long x) throws SQLException {

}

@Override
public void writeFloat(float x) throws SQLException {

}

@Override
public void writeDouble(double x) throws SQLException {

}

@Override
public void writeBigDecimal(BigDecimal x) throws SQLException {

}

@Override
public void writeBytes(byte[] x) throws SQLException {

}

@Override
public void writeDate(Date x) throws SQLException {

}

@Override
public void writeTime(Time x) throws SQLException {

}

@Override
public void writeTimestamp(Timestamp x) throws SQLException {

}

@Override
public void writeCharacterStream(Reader x) throws SQLException {

}

@Override
public void writeAsciiStream(InputStream x) throws SQLException {

}

@Override
public void writeBinaryStream(InputStream x) throws SQLException {

}

@Override
public void writeObject(SQLData x) throws SQLException {
try {
attribs.add(OBJECT_MAPPER.writeValueAsString(x));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

@Override
public void writeRef(Ref x) throws SQLException {

}

@Override
public void writeBlob(Blob x) throws SQLException {

}

@Override
public void writeClob(Clob x) throws SQLException {

}

@Override
public void writeStruct(Struct x) throws SQLException {

}

@Override
public void writeArray(Array x) throws SQLException {

}

@Override
public void writeURL(URL x) throws SQLException {

}

@Override
public void writeNString(String x) throws SQLException {

}

@Override
public void writeNClob(NClob x) throws SQLException {

}

@Override
public void writeRowId(RowId x) throws SQLException {

}

@Override
public void writeSQLXML(SQLXML x) throws SQLException {

}
}

25 changes: 25 additions & 0 deletions src/main/java/net/snowflake/client/jdbc/ColumnTypeInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.snowflake.client.jdbc;

public class ColumnTypeInfo {
private int columnType;
private String extColTypeName;
private SnowflakeType snowflakeType;

public ColumnTypeInfo(int columnType, String extColTypeName, SnowflakeType snowflakeType) {
this.columnType = columnType;
this.extColTypeName = extColTypeName;
this.snowflakeType = snowflakeType;
}

public int getColumnType() {
return columnType;
}

public String getExtColTypeName() {
return extColTypeName;
}

public SnowflakeType getSnowflakeType() {
return snowflakeType;
}
}
115 changes: 115 additions & 0 deletions src/main/java/net/snowflake/client/jdbc/MetadataField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package net.snowflake.client.jdbc;

import com.fasterxml.jackson.annotation.JsonProperty;

public class MetadataField {

public MetadataField() {
}

private String name;
private String typeName;
private int type;
private boolean nullable;
@JsonProperty("byteLength")
private int length;
private int precision;
private int scale;
private boolean fixed;
private SnowflakeType base;
private MetadataField[] fields;

public MetadataField(String name, String typeName, int type, boolean nullable, int length, int precision,
int scale, boolean fixed, SnowflakeType base, MetadataField[] fields) {
this.name = name;
this.typeName = typeName;
this.type = type;
this.nullable = nullable;
this.length = length;
this.precision = precision;
this.scale = scale;
this.fixed = fixed;
this.base = base;
this.fields = fields;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getTypeName() {
return typeName;
}

public void setTypeName(String typeName) {
this.typeName = typeName;
}

public int getType() {
return type;
}

public void setType(int type) {
this.type = type;
}

public boolean isNullable() {
return nullable;
}

public void setNullable(boolean nullable) {
this.nullable = nullable;
}

public int getLength() {
return length;
}

public void setLength(int length) {
this.length = length;
}

public int getPrecision() {
return precision;
}

public void setPrecision(int precision) {
this.precision = precision;
}

public int getScale() {
return scale;
}

public void setScale(int scale) {
this.scale = scale;
}

public boolean isFixed() {
return fixed;
}

public void setFixed(boolean fixed) {
this.fixed = fixed;
}

public SnowflakeType getBase() {
return base;
}

public void setBase(SnowflakeType base) {
this.base = base;
}

public MetadataField[] getFields() {
return fields;
}

public void setFields(MetadataField[] fields) {
this.fields = fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SnowflakeColumnMetadata implements Serializable {
private int scale;
private boolean fixed;
private SnowflakeType base;
private MetadataField[] fields;
private String columnSrcTable;
private String columnSrcSchema;
private String columnSrcDatabase;
Expand All @@ -36,6 +37,7 @@ public SnowflakeColumnMetadata(
String typeName,
boolean fixed,
SnowflakeType base,
MetadataField[] fields,
String columnSrcDatabase,
String columnSrcSchema,
String columnSrcTable,
Expand All @@ -49,6 +51,7 @@ public SnowflakeColumnMetadata(
this.typeName = typeName;
this.fixed = fixed;
this.base = base;
this.fields = fields;
this.columnSrcDatabase = columnSrcDatabase;
this.columnSrcSchema = columnSrcSchema;
this.columnSrcTable = columnSrcTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ public void setObject(int parameterIndex, Object x) throws SQLException {
setBoolean(parameterIndex, (Boolean) x);
} else if (x instanceof byte[]) {
setBytes(parameterIndex, (byte[]) x);
// } else if (x instanceof SQLData) {
// JsonSQLOutput sqlOutput = new JsonSQLOutput();
// ((SQLData) x).writeSql(sqlOutput);
// setString(parameterIndex, sqlOutput.getJsonString());
} else {
throw new SnowflakeSQLLoggedException(
connection.getSFBaseSession(),
Expand Down
Loading

0 comments on commit ff12158

Please sign in to comment.