我正在使用apache avro並希望從我的模式中獲取邏輯類型。我嘗試使用函數getLogicalType()
,但它返回null。我不明白什麼是錯的。我的模式如下。apache avro api的getLogicalType()函數即使存在也會返回null
{
"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": "int", "logicalType": "decimal", "precision": 2, "scale": "2"},
{"name": "favorite_color", "type": ["string", "null"]}
]
}
以下是我在哪裏訪問logicalType
for(Schema.Field currField : schema.getFields()) {
field = createFieldList(currField.name(), currField.schema().getType().toString(), currField.schema().getLogicalType());
fields.add(field);
}
正如我在評論中寫道,以我的回答你有爲所有字段循環,並且只爲第二個字段定義* logicalType *,這就是爲什麼getLogicalType()返回null,至少對於第一個和第三個字段。嘗試僅爲每個字段輸出getLogicalType的結果,而不是在createFieldList()中使用它。 – LLL
不,它打印全部爲空 – Hazzard