Skip to content

Commit d1b655b

Browse files
committed
renaming, added extra constructors for TypeInformation, restricting types
1 parent f96234d commit d1b655b

File tree

9 files changed

+270
-273
lines changed

9 files changed

+270
-273
lines changed

dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/db/DbColumnTypeInformation.kt

Lines changed: 0 additions & 124 deletions
This file was deleted.

dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/db/DbType.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ public abstract class DbType(public val dbTypeInJdbcUrl: String) {
134134
Types.TIMESTAMP_WITH_TIMEZONE to typeOf<OffsetDateTime>(),
135135
)
136136

137-
private val typeInformationCache = mutableMapOf<TableColumnMetadata, AnyDbColumnTypeInformation>()
137+
private val typeInformationCache = mutableMapOf<TableColumnMetadata, AnyTypeInformation>()
138138

139139
/**
140-
* Returns a [DbColumnTypeInformation] produced from [tableColumnMetadata].
140+
* Returns a [TypeInformation] produced from [tableColumnMetadata].
141141
*/
142-
public fun getOrGenerateTypeInformation(tableColumnMetadata: TableColumnMetadata): AnyDbColumnTypeInformation =
142+
public fun getOrGenerateTypeInformation(tableColumnMetadata: TableColumnMetadata): AnyTypeInformation =
143143
typeInformationCache.getOrPut(tableColumnMetadata) { generateTypeInformation(tableColumnMetadata) }
144144

145145
/**
146-
* Returns a [DbColumnTypeInformation] produced from [tableColumnMetadata].
146+
* Returns a [TypeInformation] produced from [tableColumnMetadata].
147147
*
148-
* This function can be overridden by returning your own [DbColumnTypeInformation] or a subtype of that.
148+
* This function can be overridden by returning your own [TypeInformation] or a subtype of that.
149149
* Do note that this class needs to be stateless, so this function can be memoized.
150150
*/
151-
public open fun generateTypeInformation(tableColumnMetadata: TableColumnMetadata): AnyDbColumnTypeInformation {
151+
public open fun generateTypeInformation(tableColumnMetadata: TableColumnMetadata): AnyTypeInformation {
152152
val kType = when {
153153
tableColumnMetadata.jdbcType == Types.OTHER ->
154154
when (tableColumnMetadata.javaClassName) {
@@ -186,16 +186,16 @@ public abstract class DbType(public val dbTypeInJdbcUrl: String) {
186186
val postprocessor =
187187
when (tableColumnMetadata.jdbcType) {
188188
Types.ARRAY ->
189-
DbColumnPostprocessor<Array<*>, Any?> { column, _ ->
189+
DbColumnPostprocessor<Array<*>, Any> { column, _ ->
190190
handleArrayValues(column.asValueColumn())
191191
}
192192

193193
else -> null
194194
}
195195

196-
return dbColumnTypeInformationWithPostprocessing<Any?, Any?>(
196+
return typeInformationWithPostprocessingFor(
197197
targetSchema = ColumnSchema.Value(kType.withNullability(tableColumnMetadata.isNullable)),
198-
columnPostprocessor = postprocessor?.cast(),
198+
columnPostprocessor = postprocessor?.castToAny(),
199199
)
200200
}
201201

@@ -208,29 +208,29 @@ public abstract class DbType(public val dbTypeInJdbcUrl: String) {
208208
* @param [typeInformation]
209209
* @return the extracted value, or null
210210
*/
211-
public open fun <J> getValueFromResultSet(
211+
public open fun <J : Any> getValueFromResultSet(
212212
rs: ResultSet,
213213
columnIndex: Int,
214-
typeInformation: DbColumnTypeInformation<J, *, *>,
215-
): J =
214+
typeInformation: TypeInformation<J, *, *>,
215+
): J? =
216216
try {
217217
rs.getObject(columnIndex + 1)
218218
} catch (_: Throwable) {
219219
// TODO?
220220
rs.getString(columnIndex + 1)
221-
} as J
221+
} as J?
222222

223-
public fun <J, D> preprocessValuesFromResultSet(
223+
public fun <J : Any, D : Any> preprocessValuesFromResultSet(
224224
value: J?,
225-
dbColumnTypeInformation: DbColumnTypeInformation<J, D, *>,
226-
): D? = dbColumnTypeInformation.preprocess(value)
225+
typeInformation: TypeInformation<J, D, *>,
226+
): D? = typeInformation.preprocess(value)
227227

228-
public open fun <D> buildDataColumn(
228+
public open fun <D : Any> buildDataColumn(
229229
name: String,
230-
values: List<D>,
231-
typeInformation: DbColumnTypeInformation<*, D, *>,
230+
values: List<D?>,
231+
typeInformation: TypeInformation<*, D, *>,
232232
inferNullability: Boolean,
233-
): DataColumn<D> =
233+
): DataColumn<D?> =
234234
when (val schema = typeInformation.targetSchema) {
235235
is ColumnSchema.Value ->
236236
DataColumn.createValueColumn(
@@ -254,10 +254,10 @@ public abstract class DbType(public val dbTypeInJdbcUrl: String) {
254254
).cast()
255255
}
256256

257-
public fun <D, P> postProcessDataColumn(
258-
column: DataColumn<D>,
259-
dbColumnTypeInformation: DbColumnTypeInformation<*, D, P>,
260-
): DataColumn<P> = dbColumnTypeInformation.postprocess(column)
257+
public fun <D : Any, P : Any> postProcessDataColumn(
258+
column: DataColumn<D?>,
259+
typeInformation: TypeInformation<*, D, P>,
260+
): DataColumn<P?> = typeInformation.postprocess(column)
261261

262262
/**
263263
* Checks if the given table name is a system table for the specified database type.

0 commit comments

Comments
 (0)