All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecwid.clickhouse.raw.RawRow.kt Maven / Gradle / Ivy

package com.ecwid.clickhouse.raw

import com.ecwid.clickhouse.Meta

data class RawRow(
	private val meta: Meta,
	private val values: List
) {

	fun getMeta() = meta

	fun getScalarValue(columnIndex: Int): String? {
		val value = values[columnIndex]
		require(value is String?) {
			"Can't convert array $value to scalar value"
		}
		return value
	}

	fun getScalarValue(columnName: String): String? {
		val columnIndex = meta.getColumnIndex(columnName)
		return getScalarValue(columnIndex)
	}

	fun getArrayValue(columnIndex: Int): List {
		val value = values[columnIndex]

		require(value is List<*>) {
			"Can't convert scalar $value to array"
		}

		@Suppress("UNCHECKED_CAST")
		return value as List
	}

	fun getArrayValue(columnName: String): List {
		val columnIndex = meta.getColumnIndex(columnName)
		return getArrayValue(columnIndex)
	}

	fun getMapValue(columnIndex: Int): Map {
		val value = values[columnIndex]

		require(value is Map<*, *>) {
			"Can't convert scalar $value to map"
		}

		@Suppress("UNCHECKED_CAST")
		return value as Map
	}

	fun getMapValue(columnName: String): Map {
		val columnIndex = meta.getColumnIndex(columnName)
		return getMapValue(columnIndex)
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy