Java 当我从 Kettle 中的 json 文件导入数据时出现内存不足错误

Java out of memory error when I import data from json file in Kettle

我尝试从 kettle 中的 json 文件导入数据,但不幸的是我遇到了 java 错误:java.lang.OutOfMemoryError: Java heap space .

我的水壶的构建版本是 5.4.0.1-130,我的数据格式如下:

[{"movie_title": "Carmen (English Subtitled)"},
{"movie_title": "Sugar Valentine"},
{"movie_title": "Segovia at Los Olivos [VHS]"},
{"movie_title": "Lost Boys of Sudan [VHS]"},
{"movie_title": "The Virgin of Juarez"},
{"movie_title": "Red Dawn ('84)"},
{"movie_title": "The Complete Story Deftones"},
{"movie_title": "It Came From Somewhere Else"},
{"movie_title": "Rubi"},
{"movie_title": "Fushigi Yugi - The Mysterious Play (Vol. 1)"},
{"movie_title": "Tenchi Universe, Vol. 4"}]

这是一个 json 文件,实际上有 210000 多条记录。

我尝试导入所有 movie_titles 并在 kettle 中选择 'Json Input' 步骤。

字段的配置如下所示:

Name : movie_title  
Path : [*].movie_title
Type : String
Trim type : none
Repeat : N

在我点击预览行后,出现错误信息,如

2015/10/25 11:45:45 - Version checker - OK
2015/10/25 15:10:23 - /Users/Chris/Desktop/exercise_2/Exercise_2_Step3.ktr : Exercise_2_Step3 - Dispatching started for transformation [/Users/Chris/Desktop/exercise_2/Exercise_2_Step3.ktr : Exercise_2_Step3]
2015/10/25 15:10:31 - Json Input.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : UnexpectedError: 
2015/10/25 15:10:31 - Json Input.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : java.lang.OutOfMemoryError: Java heap space
2015/10/25 15:10:31 - Json Input.0 - Finished processing (I=0, O=0, R=0, W=0, U=0, E=1)
2015/10/25 15:10:31 - /Users/Chris/Desktop/exercise_2/Exercise_2_Step3.ktr : Exercise_2_Step3 - Transformation detected one or more steps with errors.
2015/10/25 15:10:31 - /Users/Chris/Desktop/exercise_2/Exercise_2_Step3.ktr : Exercise_2_Step3 - Transformation is killing the other steps!

有谁知道如何解决这个问题?

我做了一些测试并得到了相同的结果 - OutOfMemoryError。 我生成 json 文件样本进行实验。

JSON 带数组的文件,包含 300000 个元素。 movie_title 字段的每个元素等于 60 个符号。

整个文件总共需要 22MB space。 Kettle 在 jvm 中使用 javascript 引擎来解析 json 因为在 class

中抛出错误
sun.org.mozilla.javascript.internal.Parser

它似乎在应用任何 JsonPath 表达式之前尝试解析整个 json 文件并将其加载到内存中。结果是 OutOfMemoryErrror。

实际上你可以做的是使用Java脚本步骤或用户定义Java Class将json文件加载到内存中并使用Java Api 解析 json.

这可能有帮助