summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-06-09 10:31:41 +0200
committerGitHub <noreply@github.com>2022-06-09 10:31:41 +0200
commitd146814bbbb86bfcb19ccb94250424703e9179e5 (patch)
treebf20f51b434d56e60ad013568ac1a32b912a3b5e /opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt
parent61b6550d7a476ab1aae45a5b9385dfd6ca4f6b6f (diff)
parent9d759c9bc987965fae8b0c16c000772c546bf3a2 (diff)
merge: Introduce schema for trace API (#88)
This pull request updates the OpenDC trace API to support proper specification of a schema of the tables exposed by the traces. This functionality makes it easier for the API consumer to understand the types exposed by the API. ## Implementation Notes :hammer_and_pick: * Introduce type system for trace API * Add benchmarks for odcvm trace format * Add benchmarks for Azure trace format * Add conformance suite for OpenDC trace API ## External Dependencies :four_leaf_clover: * N/A ## Breaking API Changes :warning: * Removal of typed `TableColumn`. Instead, `TableColumn` instances are now used to describe the columns belonging to some table. * `TableReader` and `TableWriter` do not support accessing arbitrary objects anymore. Instead, only the types supported by the type system are exposed.
Diffstat (limited to 'opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt')
-rw-r--r--opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt197
1 files changed, 161 insertions, 36 deletions
diff --git a/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt b/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt
index 423ce86a..a3122ec9 100644
--- a/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt
+++ b/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/TableWriter.kt
@@ -22,6 +22,10 @@
package org.opendc.trace
+import java.time.Duration
+import java.time.Instant
+import java.util.*
+
/**
* Base class for writing workload traces.
*/
@@ -37,107 +41,228 @@ public interface TableWriter : AutoCloseable {
public fun endRow()
/**
- * Resolve the index of the specified [column] for this writer.
+ * Resolve the index of the column named [name] for this writer.
*
- * @param column The column to lookup.
+ * @param name The name of the column to lookup.
* @return The zero-based index of the column or a negative value if the column is not present in this table.
*/
- public fun resolve(column: TableColumn<*>): Int
+ public fun resolve(name: String): Int
/**
- * Determine whether the [TableReader] supports the specified [column].
+ * Set the column with index [index] to boolean [value].
+ *
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The boolean value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun hasColumn(column: TableColumn<*>): Boolean = resolve(column) >= 0
+ public fun setBoolean(index: Int, value: Boolean)
/**
- * Set [column] to [value].
+ * Set the column with index [index] to integer [value].
*
* @param index The zero-based index of the column to set the value for.
- * @param value The value to set the column to.
+ * @param value The integer value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun set(index: Int, value: Any)
+ public fun setInt(index: Int, value: Int)
/**
- * Set [column] to boolean [value].
+ * Set the column with index [index] to long [value].
*
* @param index The zero-based index of the column to set the value for.
- * @param value The boolean value to set the column to.
+ * @param value The long value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setBoolean(index: Int, value: Boolean)
+ public fun setLong(index: Int, value: Long)
/**
- * Set [column] to integer [value].
+ * Set the column with index [index] to float [value].
*
* @param index The zero-based index of the column to set the value for.
- * @param value The integer value to set the column to.
+ * @param value The float value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setInt(index: Int, value: Int)
+ public fun setFloat(index: Int, value: Float)
/**
- * Set [column] to long [value].
+ * Set the column with index [index] to double [value].
*
* @param index The zero-based index of the column to set the value for.
- * @param value The long value to set the column to.
+ * @param value The double value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setLong(index: Int, value: Long)
+ public fun setDouble(index: Int, value: Double)
/**
- * Set [column] to double [value].
+ * Set the column with index [index] to [String] [value].
*
* @param index The zero-based index of the column to set the value for.
- * @param value The double value to set the column to.
+ * @param value The [String] value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setDouble(index: Int, value: Double)
+ public fun setString(index: Int, value: String)
+
+ /**
+ * Set the column with index [index] to [UUID] [value].
+ *
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The [UUID] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setUUID(index: Int, value: UUID)
+
+ /**
+ * Set the column with index [index] to [Instant] [value].
+ *
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The [Instant] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setInstant(index: Int, value: Instant)
/**
- * Set [column] to [value].
+ * Set the column with index [index] to [Duration] [value].
*
- * @param column The column to set the value for.
- * @param value The value to set the column to.
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The [Duration] value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun <T : Any> set(column: TableColumn<T>, value: T): Unit = set(resolve(column), value)
+ public fun setDuration(index: Int, value: Duration)
/**
- * Set [column] to boolean [value].
+ * Set the column with index [index] to [List] [value].
*
- * @param column The column to set the value for.
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The [Map] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun <T> setList(index: Int, value: List<T>)
+
+ /**
+ * Set the column with index [index] to [Set] [value].
+ *
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The [Set] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun <T> setSet(index: Int, value: Set<T>)
+
+ /**
+ * Set the column with index [index] to [Map] [value].
+ *
+ * @param index The zero-based index of the column to set the value for.
+ * @param value The [Map] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun <K, V> setMap(index: Int, value: Map<K, V>)
+
+ /**
+ * Set the column named [name] to boolean [value].
+ *
+ * @param name The name of the column to set the value for.
* @param value The boolean value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setBoolean(column: TableColumn<Boolean>, value: Boolean): Unit = setBoolean(resolve(column), value)
+ public fun setBoolean(name: String, value: Boolean): Unit = setBoolean(resolve(name), value)
/**
- * Set [column] to integer [value].
+ * Set the column named [name] to integer [value].
*
- * @param column The column to set the value for.
+ * @param name The name of the column to set the value for.
* @param value The integer value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setInt(column: TableColumn<Int>, value: Int): Unit = setInt(resolve(column), value)
+ public fun setInt(name: String, value: Int): Unit = setInt(resolve(name), value)
/**
- * Set [column] to long [value].
+ * Set the column named [name] to long [value].
*
- * @param column The column to set the value for.
+ * @param name The name of the column to set the value for.
* @param value The long value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setLong(column: TableColumn<Long>, value: Long): Unit = setLong(resolve(column), value)
+ public fun setLong(name: String, value: Long): Unit = setLong(resolve(name), value)
+
+ /**
+ * Set the column named [name] to float [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The float value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setFloat(name: String, value: Float): Unit = setFloat(resolve(name), value)
/**
- * Set [column] to double [value].
+ * Set the column named [name] to double [value].
*
- * @param column The column to set the value for.
+ * @param name The name of the column to set the value for.
* @param value The double value to set the column to.
* @throws IllegalArgumentException if the column is not valid for this method.
*/
- public fun setDouble(column: TableColumn<Double>, value: Double): Unit = setDouble(resolve(column), value)
+ public fun setDouble(name: String, value: Double): Unit = setDouble(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [String] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [String] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setString(name: String, value: String): Unit = setString(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [UUID] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [UUID] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setUUID(name: String, value: UUID): Unit = setUUID(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [Instant] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [Instant] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setInstant(name: String, value: Instant): Unit = setInstant(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [Duration] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [Duration] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun setDuration(name: String, value: Duration): Unit = setDuration(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [List] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [List] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun <T> setList(name: String, value: List<T>): Unit = setList(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [Set] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [Set] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun <T> setSet(name: String, value: Set<T>): Unit = setSet(resolve(name), value)
+
+ /**
+ * Set the column named [name] to [Map] [value].
+ *
+ * @param name The name of the column to set the value for.
+ * @param value The [Map] value to set the column to.
+ * @throws IllegalArgumentException if the column is not valid for this method.
+ */
+ public fun <K, V> setMap(name: String, value: Map<K, V>): Unit = setMap(resolve(name), value)
/**
* Flush any buffered content to the underlying target.