Skip to content

Instantly share code, notes, and snippets.

@iamsmkr
Last active July 19, 2022 06:15
Show Gist options
  • Save iamsmkr/f120f32f553b09ac92dd369440c45dc3 to your computer and use it in GitHub Desktop.
Save iamsmkr/f120f32f553b09ac92dd369440c45dc3 to your computer and use it in GitHub Desktop.
private val allocator: BufferAllocator = new RootAllocator()
private val schema: Schema =
new Schema(List(
new Field("id", new FieldType(false, new ArrowType.Int(32, true), null), null),
new Field("username", new FieldType(false, new ArrowType.Utf8(), null), null),
new Field("pro", new FieldType(false, new ArrowType.Bool(), null), null)
).asJava)
private val vectorSchemaRoot = VectorSchemaRoot.create(schema, allocator)
val id = vectorSchemaRoot.getVector("id").asInstanceOf[IntVector]
val username = vectorSchemaRoot.getVector("username").asInstanceOf[VarCharVector]
val pro = vectorSchemaRoot.getVector("pro").asInstanceOf[BitVector]
val ls = List(1000, "iamsmkr", true)
val vectors = List(id, username, pro)
ls.zip(vectors).map { (value, vector) =>
vector.allocateNew()
vector.setSafe(0, value)
vector.setValueCount(1)
vector.get(0)
}
// Returned is the list of values as a validation of value vectors being set correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment