Package com.databricks.jdbc.common.util
Class DatabricksTypeUtil
- java.lang.Object
-
- com.databricks.jdbc.common.util.DatabricksTypeUtil
-
public class DatabricksTypeUtil extends Object
Utility class for handling various type conversions and mappings between Databricks-specific data types, SQL types, and Arrow types.
-
-
Field Summary
Fields Modifier and Type Field Description static StringARRAYstatic StringBIGINTstatic StringBINARYstatic StringBOOLEANstatic StringBYTEstatic StringCHARstatic StringDATEstatic StringDECstatic StringDECIMALstatic StringDOUBLEstatic StringFLOATstatic StringGEOGRAPHYstatic StringGEOGRAPHY_CLASS_NAMEstatic StringGEOMETRYstatic StringGEOMETRY_CLASS_NAMEstatic StringINTstatic StringINTEGERstatic StringINTERVALstatic StringLONGstatic StringMAPstatic StringMEASUREstatic StringNCHARstatic StringNULLstatic StringNUMERICstatic StringNVARCHARstatic StringREALstatic StringSHORTstatic StringSMALLINTstatic StringSTRINGstatic StringSTRUCTstatic StringTIMEstatic StringTIMESTAMPstatic StringTIMESTAMP_NTZstatic StringTINYINTstatic StringVARCHARstatic StringVARIANTstatic StringVOID
-
Constructor Summary
Constructors Constructor Description DatabricksTypeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]getBasePrecisionAndScale(int columnType, IDatabricksConnectionContext ctx)static ColumnInfoTypeNamegetColumnInfoType(String typeName)Maps a SQL type name (as returned by DESCRIBE QUERY or schema metadata) to the correspondingColumnInfoTypeName.static intgetColumnType(ColumnInfoTypeName typeName)static StringgetColumnTypeClassName(ColumnInfoTypeName typeName)static StringgetDatabricksTypeFromSQLType(int sqlType)Converts SQL type into Databricks type as defined herestatic StringgetDecimalTypeString(BigDecimal bd)static intgetDisplaySize(int sqlType, int precision)Returns the display size for a given SQL type and precision.static intgetDisplaySize(ColumnInfoTypeName typeName, int precision, int scale)static intgetMetadataColPrecision(Integer columnType)static NullablegetNullableFromValue(Integer isNullable)static intgetPrecision(Integer columnType)static intgetScale(Integer columnType)static TPrimitiveTypeEntrygetTPrimitiveTypeOrDefault(TTypeDesc typeDesc)static StringinferDatabricksType(Object obj)Infers Databricks type from class of given object as defined in herestatic booleanisComplexType(String typeName)Checks if the given type name represents a complex type (ARRAY, MAP, STRUCT).static booleanisDate(Object obj)static booleanisGeospatialType(String typeName)Checks if the given type name represents a geospatial type (GEOMETRY, GEOGRAPHY).static booleanisSigned(ColumnInfoTypeName typeName)static booleanisTemporalType(Object obj)static booleanisTimestamp(Object obj)static org.apache.arrow.vector.types.pojo.ArrowTypemapThriftToArrowType(TTypeId typeId)
-
-
-
Field Detail
-
BIGINT
public static final String BIGINT
- See Also:
- Constant Field Values
-
LONG
public static final String LONG
- See Also:
- Constant Field Values
-
BINARY
public static final String BINARY
- See Also:
- Constant Field Values
-
BOOLEAN
public static final String BOOLEAN
- See Also:
- Constant Field Values
-
DATE
public static final String DATE
- See Also:
- Constant Field Values
-
DECIMAL
public static final String DECIMAL
- See Also:
- Constant Field Values
-
DOUBLE
public static final String DOUBLE
- See Also:
- Constant Field Values
-
FLOAT
public static final String FLOAT
- See Also:
- Constant Field Values
-
INT
public static final String INT
- See Also:
- Constant Field Values
-
BYTE
public static final String BYTE
- See Also:
- Constant Field Values
-
VOID
public static final String VOID
- See Also:
- Constant Field Values
-
SHORT
public static final String SHORT
- See Also:
- Constant Field Values
-
SMALLINT
public static final String SMALLINT
- See Also:
- Constant Field Values
-
NULL
public static final String NULL
- See Also:
- Constant Field Values
-
STRING
public static final String STRING
- See Also:
- Constant Field Values
-
TINYINT
public static final String TINYINT
- See Also:
- Constant Field Values
-
TIMESTAMP
public static final String TIMESTAMP
- See Also:
- Constant Field Values
-
TIME
public static final String TIME
- See Also:
- Constant Field Values
-
TIMESTAMP_NTZ
public static final String TIMESTAMP_NTZ
- See Also:
- Constant Field Values
-
MAP
public static final String MAP
- See Also:
- Constant Field Values
-
ARRAY
public static final String ARRAY
- See Also:
- Constant Field Values
-
STRUCT
public static final String STRUCT
- See Also:
- Constant Field Values
-
VARIANT
public static final String VARIANT
- See Also:
- Constant Field Values
-
CHAR
public static final String CHAR
- See Also:
- Constant Field Values
-
GEOMETRY
public static final String GEOMETRY
- See Also:
- Constant Field Values
-
GEOGRAPHY
public static final String GEOGRAPHY
- See Also:
- Constant Field Values
-
INTERVAL
public static final String INTERVAL
- See Also:
- Constant Field Values
-
VARCHAR
public static final String VARCHAR
- See Also:
- Constant Field Values
-
NVARCHAR
public static final String NVARCHAR
- See Also:
- Constant Field Values
-
NCHAR
public static final String NCHAR
- See Also:
- Constant Field Values
-
INTEGER
public static final String INTEGER
- See Also:
- Constant Field Values
-
NUMERIC
public static final String NUMERIC
- See Also:
- Constant Field Values
-
DEC
public static final String DEC
- See Also:
- Constant Field Values
-
REAL
public static final String REAL
- See Also:
- Constant Field Values
-
GEOMETRY_CLASS_NAME
public static final String GEOMETRY_CLASS_NAME
- See Also:
- Constant Field Values
-
GEOGRAPHY_CLASS_NAME
public static final String GEOGRAPHY_CLASS_NAME
- See Also:
- Constant Field Values
-
MEASURE
public static final String MEASURE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getColumnInfoType
public static ColumnInfoTypeName getColumnInfoType(String typeName)
Maps a SQL type name (as returned by DESCRIBE QUERY or schema metadata) to the correspondingColumnInfoTypeName. Handles canonical names, Databricks aliases, and standard SQL aliases (VARCHAR, INTEGER, NUMERIC, DEC, REAL, NVARCHAR, NCHAR). ReturnsColumnInfoTypeName.USER_DEFINED_TYPEfor unrecognized types.
-
getColumnType
public static int getColumnType(ColumnInfoTypeName typeName)
-
getColumnTypeClassName
public static String getColumnTypeClassName(ColumnInfoTypeName typeName)
-
getBasePrecisionAndScale
public static int[] getBasePrecisionAndScale(int columnType, IDatabricksConnectionContext ctx)
-
getDisplaySize
public static int getDisplaySize(ColumnInfoTypeName typeName, int precision, int scale)
-
getDisplaySize
public static int getDisplaySize(int sqlType, int precision)Returns the display size for a given SQL type and precision. This method is used only in pre-defined result set metadata flow.- Parameters:
sqlType- the SQL type as defined inTypesprecision- the precision of the column- Returns:
- the display size for the given SQL type and precision
-
getMetadataColPrecision
public static int getMetadataColPrecision(Integer columnType)
-
getPrecision
public static int getPrecision(Integer columnType)
-
getScale
public static int getScale(Integer columnType)
-
isSigned
public static boolean isSigned(ColumnInfoTypeName typeName)
-
getDatabricksTypeFromSQLType
public static String getDatabricksTypeFromSQLType(int sqlType)
Converts SQL type into Databricks type as defined here- Parameters:
sqlType- SQL type input- Returns:
- databricks type
-
inferDatabricksType
public static String inferDatabricksType(Object obj)
Infers Databricks type from class of given object as defined in here- Parameters:
obj- input object- Returns:
- inferred Databricks type
-
isTimestamp
public static boolean isTimestamp(Object obj)
-
isDate
public static boolean isDate(Object obj)
-
isTemporalType
public static boolean isTemporalType(Object obj)
-
getTPrimitiveTypeOrDefault
public static TPrimitiveTypeEntry getTPrimitiveTypeOrDefault(TTypeDesc typeDesc)
-
mapThriftToArrowType
public static org.apache.arrow.vector.types.pojo.ArrowType mapThriftToArrowType(TTypeId typeId) throws SQLException
- Throws:
SQLException
-
getDecimalTypeString
public static String getDecimalTypeString(BigDecimal bd)
-
isComplexType
public static boolean isComplexType(String typeName)
Checks if the given type name represents a complex type (ARRAY, MAP, STRUCT).- Parameters:
typeName- The type name to check- Returns:
- true if the type name starts with ARRAY, MAP, or STRUCT
-
isGeospatialType
public static boolean isGeospatialType(String typeName)
Checks if the given type name represents a geospatial type (GEOMETRY, GEOGRAPHY).- Parameters:
typeName- The type name to check- Returns:
- true if the type name starts with GEOMETRY or GEOGRAPHY
-
-