Last active
July 23, 2022 09:09
-
-
Save iamsmkr/610420d2c563e890d5881a349a3041f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ids = vectorSchemaRoot.getVector("id").asInstanceOf[IntVector] | |
val usernames = vectorSchemaRoot.getVector("username").asInstanceOf[VarCharVector] | |
val pros = vectorSchemaRoot.getVector("pro").asInstanceOf[BitVector] | |
case class User( | |
id: Int = 0, | |
username: String = "", | |
pro: Boolean = false | |
) | |
case class UserVectors( | |
ids: IntVector, | |
usernames: VarCharVector, | |
pros: BitVector | |
) | |
private val vectors = | |
UserVectors( | |
ids, | |
usernames, | |
pros | |
) | |
private val user = | |
User( | |
1000, | |
"iamsmkr", | |
true | |
) | |
// allocate new buffers | |
AllocateNew[UserVectors].allocateNew(vectors) | |
// set values to vectors | |
SetSafe[UserVectors, User].setSafe(vectors, 0, user) | |
// set value count | |
SetValueCount[UserVectors].setValueCount(vectors, 1) | |
// check if values are set against a given row | |
assert(IsSet[UserVectors].isSet(vectors, 0).forall(_ == 1)) | |
// get values against a row | |
val encoded = Get[UserVectors, User].invokeGet(vectors, 0) | |
assert(encoded == user) | |
// close resources | |
Close[UserVectors].close(vectors) | |
vectorSchemaRoot.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment