hudi icon indicating copy to clipboard operation
hudi copied to clipboard

Hudi deltastreamer using avro schema parser when using jsonKafkaSource

Open shivabodepudi opened this issue 5 years ago • 10 comments

when trying to read data from Kafka which is stored as Json from schema registry. using below configuration.

"--schemaprovider-class", "org.apache.hudi.utilities.schema.SchemaRegistryProvider", "--source-class", "org.apache.hudi.utilities.sources.JsonKafkaSource", "--continuous", "--table-type", "COPY_ON_WRITE", "--hoodie-conf", "hoodie.deltastreamer.schemaprovider.registry.url=https://localhost/subjects/testtopic-value/versions/latest",

Environment Description

  • Hudi version :0.8.0

  • Spark version :

  • Hive version :

  • Hadoop version :

  • Storage (HDFS/S3/GCS..) :s3

  • Running on Docker? (yes/no) : No

Below is the error am getting. image

shivabodepudi avatar Oct 20 '21 14:10 shivabodepudi

object is not a valid type in Avro. Apart from the primitive types, Avro supports following types: records, array, map, enum, fixed and error. Not sure where is object coming from. Can you share the schema from the schema registry?

codope avatar Oct 20 '21 14:10 codope

As I am using JsonKafka source, not sure why avro is coming into picture.

shivabodepudi avatar Oct 20 '21 15:10 shivabodepudi

@shivabodepudi can you provide a sample schema from your schema registry? and also a sample kafka message? we should examine those first.

xushiyan avatar Oct 20 '21 17:10 xushiyan

below is the schema we are using right now. @xushiyan @codope

{
	"type": "object",
	"title": "testtopic.Value",
	"properties": {
		"Zipcode": {
			"type": "string",
			"connect.index": 8
		},
		"__snapshot": {
			"connect.index": 98,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string",
					"title": "io.debezium.data.Enum",
					"connect.version": 1,
					"connect.parameters": {
						"allowed": "true,last,false"
					}
				}
			]
		},
		"__change_lsn": {
			"connect.index": 103,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		"Last_Upd_DateTime": {
			"type": "integer",
			"title": "io.debezium.time.Timestamp",
			"connect.index": 62,
			"connect.version": 1,
			"connect.type": "int64"
		},
		"Crt_DateTime": {
			"type": "integer",
			"title": "io.debezium.time.Timestamp",
			"connect.index": 59,
			"connect.version": 1,
			"connect.type": "int64"
		},
		"Description": {
			"connect.index": 3,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		"BillTo_Address2": {
			"type": "string",
			"connect.index": 16
		},
		"BillTo_Address1": {
			"type": "string",
			"connect.index": 15
		},
		"Time_Zone": {
			"type": "integer",
			"connect.index": 12,
			"connect.type": "int16"
		},
		"_hoodie_is_deleted": {
			"connect.index": 104,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "boolean"
				}
			]
		},
		"__schema": {
			"connect.index": 102,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		"Last_Upd_UserNum": {
			"type": "integer",
			"connect.index": 60,
			"connect.type": "int32"
		},
		"__db": {
			"connect.index": 101,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		"ClinicPK": {
			"type": "string",
			"connect.index": 51
		},
		"Clinic_Num": {
			"type": "integer",
			"connect.index": 2,
			"connect.type": "int32"
		},
		"__ts_ms": {
			"connect.index": 97,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "integer",
					"connect.type": "int64"
				}
			]
		},
		"__name": {
			"connect.index": 100,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		"IsCCEnabled": {
			"connect.index": 53,
			"type": "boolean"
		},
		"Clinic_Name": {
			"type": "string",
			"connect.index": 1
		},
		"Address2": {
			"type": "string",
			"connect.index": 5
		},
		"Address1": {
			"type": "string",
			"connect.index": 4
		},
		"__op": {
			"connect.index": 95,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		
		"__table": {
			"connect.index": 96,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		},
		"__connector": {
			"connect.index": 99,
			"oneOf": [
				{
					"type": "null"
				},
				{
					"type": "string"
				}
			]
		}
	}
}

shivabodepudi avatar Oct 21 '21 06:10 shivabodepudi

@shivabodepudi I see. The problem is you're using Json schema. The schema provider org.apache.hudi.schema.SchemaProvider defines only avro schema to be provided. You could extend org.apache.hudi.schema.SchemaRegistryProvider to convert the json schema into avro by overriding org.apache.hudi.schema.SchemaRegistryProvider#fetchSchemaFromRegistry

Meanwhile i do think support json schema makes sense as we support JsonSource anyway. Filing a JIRA for this. https://issues.apache.org/jira/browse/HUDI-2608 @shivabodepudi if you interested, feel free to pick up this feature.

xushiyan avatar Oct 24 '21 23:10 xushiyan

@xushiyan @shivabodepudi I am running into the same error with JsonSchema. Is there a library that works well for the json -> avro schema conversion?

abhishekkh avatar Nov 16 '22 20:11 abhishekkh

@xushiyan @shivabodepudi I am running into the same error with JsonSchema. Is there a library that works well for the json -> avro schema conversion?

@abhishekkh we'll support this in the upcoming 0.13.0. see https://github.com/apache/hudi/pull/7727

xushiyan avatar Jan 24 '23 19:01 xushiyan

@xushiyan I was able to make this work in my fork #7463

abhishekkh avatar Jan 24 '23 21:01 abhishekkh

@xushiyan I was able to make this work in my fork #7463

@abhishekkh we landed https://github.com/apache/hudi/pull/7727 in master. A config was introduced to configure for json conversion (refer to the PR description). please try it out and let us know how it works out.

xushiyan avatar Jan 24 '23 21:01 xushiyan

Sure will give it a try

abhishekkh avatar Jan 25 '23 01:01 abhishekkh