You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2019/10/28 16:09:24 UTC
[GitHub] [incubator-iceberg] Fokko opened a new pull request #587: Improve
docs on converting the Avro schema
Fokko opened a new pull request #587: Improve docs on converting the Avro schema
URL: https://github.com/apache/incubator-iceberg/pull/587
Small improvements on:
- Add Apache prefix at some places
- Fix the import of the Apache Avro Parse
- Add example on how to add the spark-runtime-jars to the --jars
The `AvroSchemaUtil` wants to have the shaded Avro schema:
```
C02VF05JHV2T:incubator-iceberg fdriesprong$ spark-shell --jars runtime/build/libs/iceberg-spark-runtime-fa64197.jar
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.4.4
/_/
Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_192)
Type in expressions to have them evaluated.
Type :help for more information.
scala> import org.apache.iceberg.avro.AvroSchemaUtil
import org.apache.iceberg.avro.AvroSchemaUtil
scala> import scala.io.Source
import scala.io.Source
scala> import org.apache.avro.Schema.Parser
import org.apache.avro.Schema.Parser
scala> val strSchema = Source.fromFile("/Users/fdriesprong/Desktop/fpa-aws-poc/acid-fs/data/beers.avsc").getLines.mkString
strSchema: String = { "type" : "record", "name" : "topLevelRecord", "fields" : [ { "name" : "seq", "type" : [ "string", "null" ] }, { "name" : "abv", "type" : [ "string", "null" ] }, { "name" : "ibu", "type" : [ "string", "null" ] }, { "name" : "id", "type" : [ "string", "null" ] }, { "name" : "name", "type" : [ "string", "null" ] }, { "name" : "style", "type" : [ "string", "null" ] }, { "name" : "brewery_id", "type" : [ "string", "null" ] }, { "name" : "ounces", "type" : [ "string", "null" ] } ]}
scala> val avroSchema = new Parser().parse(strSchema)
avroSchema: org.apache.avro.Schema = {"type":"record","name":"topLevelRecord","fields":[{"name":"seq","type":["string","null"]},{"name":"abv","type":["string","null"]},{"name":"ibu","type":["string","null"]},{"name":"id","type":["string","null"]},{"name":"name","type":["string","null"]},{"name":"style","type":["string","null"]},{"name":"brewery_id","type":["string","null"]},{"name":"ounces","type":["string","null"]}]}
scala> val schema = AvroSchemaUtil.convert(avroSchema)
<console>:28: error: overloaded method value convert with alternatives:
(x$1: org.apache.iceberg.shaded.org.apache.avro.Schema)org.apache.iceberg.types.Type <and>
(x$1: org.apache.iceberg.types.Type)org.apache.iceberg.shaded.org.apache.avro.Schema
cannot be applied to (org.apache.avro.Schema)
val schema = AvroSchemaUtil.convert(avroSchema)
```
Passing the shaded version is bueno:
```
C02VF05JHV2T:incubator-iceberg fdriesprong$ spark-shell --jars runtime/build/libs/iceberg-spark-runtime-fa64197.jar
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.4.4
/_/
Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_192)
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.io.Source
import scala.io.Source
scala> import org.apache.iceberg.shaded.org.apache.avro.Schema.Parser
import org.apache.iceberg.shaded.org.apache.avro.Schema.Parser
scala> import org.apache.iceberg.avro.AvroSchemaUtil
import org.apache.iceberg.avro.AvroSchemaUtil
scala> val strSchema = Source.fromFile("/Users/fdriesprong/Desktop/fpa-aws-poc/acid-fs/data/beers.avsc").getLines.mkString
strSchema: String = { "type" : "record", "name" : "topLevelRecord", "fields" : [ { "name" : "seq", "type" : [ "string", "null" ] }, { "name" : "abv", "type" : [ "string", "null" ] }, { "name" : "ibu", "type" : [ "string", "null" ] }, { "name" : "id", "type" : [ "string", "null" ] }, { "name" : "name", "type" : [ "string", "null" ] }, { "name" : "style", "type" : [ "string", "null" ] }, { "name" : "brewery_id", "type" : [ "string", "null" ] }, { "name" : "ounces", "type" : [ "string", "null" ] } ]}
scala> val avroSchema = new Parser().parse(strSchema)
avroSchema: org.apache.iceberg.shaded.org.apache.avro.Schema = {"type":"record","name":"topLevelRecord","fields":[{"name":"seq","type":["string","null"]},{"name":"abv","type":["string","null"]},{"name":"ibu","type":["string","null"]},{"name":"id","type":["string","null"]},{"name":"name","type":["string","null"]},{"name":"style","type":["string","null"]},{"name":"brewery_id","type":["string","null"]},{"name":"ounces","type":["string","null"]}]}
scala> val schema = AvroSchemaUtil.convert(avroSchema)
schema: org.apache.iceberg.types.Type = struct<0: seq: optional string, 1: abv: optional string, 2: ibu: optional string, 3: id: optional string, 4: name: optional string, 5: style: optional string, 6: brewery_id: optional string, 7: ounces: optional string>
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org