selectObjectContent

fun S3AsyncClient.selectObjectContent(request: SelectObjectContentRequest.Builder.() -> Unit): Flow<SelectObjectContentEventStream>

A function that performs a select object content operation on a file from an Amazon S3 bucket, which allows retrieving a subset of data from an object by using simple SQL expressions.

The function uses S3AsyncClient and processes the results as a flow.

Return

Returns a flow of SelectObjectContentEventStream representing the content of the selected object.

Example usage:

val client = S3AsyncClient.create()

val selectObjectContentFlow = client.selectObjectContent {
bucket("people-bucket")
key("people-data.csv")
expression("SELECT * FROM S3Object s WHERE s.age 25")
expressionType(ExpressionType.SQL)
inputSerialization { serialization ->
serialization.csv { it.fileHeaderInfo(FileHeaderInfo.USE) }
}
outputSerialization {
csv(CsvOutputSerialization.builder().build())
}
}

selectObjectContentFlow
.filterIsInstance<RecordsEvent>()
.collect { event ->
val record = String(event.payload().asUtf8String())
// You may use the connector-format-csv module as well
val (id, name, age) = record.split(",")
println("Id: $id, Name: $name, Age: $age")
}
}

Parameters

request

A lambda function with SelectObjectContentRequest.Builder receiver to configure the request.