Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use base64 encoding #3003

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import scala.jdk.CollectionConverters._
*/
private[bigquery] trait ToTableRow {
private lazy val encodingPropName: String = "bigquery.bytes.encoder"
private lazy val base64Encoding: BaseEncoding = BaseEncoding.base64Url()
private lazy val base64Encoding: BaseEncoding = BaseEncoding.base64()
private lazy val hexEncoding: BaseEncoding = BaseEncoding.base16()

// YYYY-[M]M-[D]D
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class ToTableRowTest extends AnyFlatSpec with Matchers {
.set("longField", 1L)
.set("doubleField", 1.0)
.set("floatField", 1f)
.set("bytesField", BaseEncoding.base64Url().encode("someBytes".getBytes))
.set("bytesField", BaseEncoding.base64().encode("%20cフーバー".getBytes))
.set("unionField", "someUnion")
.set("arrayField", List(new TableRow().set("nestedField", "nestedValue")).asJava)
.set("mapField", List(new TableRow().set("key", "mapKey").set("value", 1.0d)).asJava)
.set("enumField", Kind.FOO.toString)
.set("fixedField", BaseEncoding.base64Url().encode("1234567890123456".getBytes))
.set("fixedField", BaseEncoding.base64().encode("%20cフーバー".getBytes))

"ToTableRow" should "convert a SpecificRecord to TableRow" in {
val specificRecord = AvroExample
Expand All @@ -54,15 +54,15 @@ class ToTableRowTest extends AnyFlatSpec with Matchers {
.setLongField(1L)
.setIntField(1)
.setFloatField(1f)
.setBytesField(ByteBuffer.wrap(ByteString.copyFromUtf8("someBytes").toByteArray))
.setBytesField(ByteBuffer.wrap(ByteString.copyFromUtf8("%20cフーバー").toByteArray))
.setArrayField(List(NestedAvro.newBuilder().setNestedField("nestedValue").build()).asJava)
.setUnionField("someUnion")
.setMapField(
Map("mapKey" -> 1.0d).asJava
.asInstanceOf[java.util.Map[java.lang.CharSequence, java.lang.Double]]
)
.setEnumField(Kind.FOO)
.setFixedField(new fixedType("1234567890123456".getBytes()))
.setFixedField(new fixedType("%20cフーバー".getBytes()))
.build()

AvroConverters.toTableRow(specificRecord) shouldEqual expectedOutput
Expand All @@ -81,7 +81,7 @@ class ToTableRowTest extends AnyFlatSpec with Matchers {
genericRecord.put("floatField", 1f)
genericRecord.put(
"bytesField",
ByteBuffer.wrap(ByteString.copyFromUtf8("someBytes").toByteArray)
ByteBuffer.wrap(ByteString.copyFromUtf8("%20cフーバー").toByteArray)
)
genericRecord.put("arrayField", List(nestedAvro).asJava)
genericRecord.put("unionField", "someUnion")
Expand All @@ -91,7 +91,7 @@ class ToTableRowTest extends AnyFlatSpec with Matchers {
.asInstanceOf[java.util.Map[java.lang.CharSequence, java.lang.Double]]
)
genericRecord.put("enumField", Kind.FOO)
genericRecord.put("fixedField", new fixedType("1234567890123456".getBytes()))
genericRecord.put("fixedField", new fixedType("%20cフーバー".getBytes()))

AvroConverters.toTableRow(genericRecord) shouldEqual expectedOutput
}
Expand All @@ -110,7 +110,7 @@ class ToTableRowTest extends AnyFlatSpec with Matchers {
.set("longField", 1L)
.set("doubleField", 1.0)
.set("floatField", 1f)
.set("bytesField", BaseEncoding.base64Url().encode("someBytes".getBytes))
.set("bytesField", BaseEncoding.base64().encode("%20cフーバー".getBytes))
.set("dateField", "2019-10-29")
.set("decimalField", decimal.toString)
.set("timeMillisField", "01:24:52.211000")
Expand All @@ -127,7 +127,7 @@ class ToTableRowTest extends AnyFlatSpec with Matchers {
.setLongField(1L)
.setIntField(1)
.setFloatField(1f)
.setBytesField(ByteBuffer.wrap(ByteString.copyFromUtf8("someBytes").toByteArray))
.setBytesField(ByteBuffer.wrap(ByteString.copyFromUtf8("%20cフーバー").toByteArray))
.setDateField(date)
.setTimeMillisField(timeMillis)
.setTimeMicrosField(timeMicros)
Expand Down