下面是我要在配置单元中导入的数据集
"1";"nyc, new york, usa";NULL
"2";"stockton, california, usa";"18"
"3";"moscow, yukon territory, russia";NULL
"4";"porto, v.n.gaia, portugal";"17"
"5";"farnborough, hants, united kingdom";NULL
"6";"santa monica, california, usa";"61"
"7";"washington, dc, usa";NULL
"8";"timmins, ontario, canada";NULL
"9";"germantown, tennessee, usa";NULL
它具有要导入为int的字符串类型的第一列,如果我将其导入为int,则该列中的所有值都保存NULL
。
因此尝试在投射后保存数据
hive> create external table bx_users(cast(userId as int) as userId, location String, cast(age as int) as age) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\;' LOCATION '/user/BX-Users';
This throws error below exception with syntax error mentioned:
NoViableAltException(50@[])
at org.apache.hadoop.hive.ql.parse.HiveParser_IdentifiersParser.identifier(HiveParser_IdentifiersParser.java:11566)
at org.apache.hadoop.hive.ql.parse.HiveParser.identifier(HiveParser.java:44909)
at org.apache.hadoop.hive.ql.parse.HiveParser.columnNameType(HiveParser.java:38559)
at org.apache.hadoop.hive.ql.parse.HiveParser.columnNameTypeList(HiveParser.java:36761)
at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:5057)
at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:2557)
at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:1589)
at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:1065)
at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:201)
at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)
at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:466)
at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1278)
at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1395)
at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1207)
at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1197)
at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:220)
at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:172)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:693)
at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:383)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:775)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:693)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:628)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
FAILED: ParseException line 1:31 cannot recognize input near 'cast' '(' 'userId' in column specification