2014-12-05 42 views
0

我正在使用Apache Avro工具從.avsc文件生成模式類。遇到我的AVRO架構中有超過300個字段的問題,這會在使用此類時導致「Java錯誤:太多參數」。 (因爲我的模式中的每個字段將是我的模式類構造函數中的一個參數)。 Java在方法中有255個參數的限制。超出方法中參數的數量

我知道我可以通過使用通用記錄(而不是Avro Tool和類生成)來解決此問題。但在我重組我的整件事之前,是否有任何解決方法?

+2

超過255個參數構造函數?這裏需要修復的是設計,我會說... – fge 2014-12-05 21:35:19

回答

1

如果一個表(類)有300個字段,那麼你的模式設計是非常糟糕的。

找到某種方法將數據分解爲多個類和多個表。

Database normalization上閱讀將是一個好的開始。

+0

我正在使用Google bigQuery,大型模式表比多個表更有效率。 – 2014-12-06 19:31:31

0

如果你的數據有很多字段,你應該重新評估你的設計。當一個消費者試圖構造這種類型的對象時,你的代碼將如何看待?

is there any workaround?

沒有,JVM specification這樣說:

The number of method parameters is limited to 255 by the definition of a method descriptor (§4.3.3), where the limit includes one unit for this in the case of instance or interface method invocations. Note that a method descriptor is defined in terms of a notion of method parameter length in which a parameter of type long or double contributes two units to the length, so parameters of these types further reduce the limit.

相關問題