0

我知道每个 hive 版本都有一些保留关键字,不能用作列名。

但问题是我的数据来自 json,而我的列名是根据 json 值。

而且我不能修改数据。有没有替代品??

这是一行样本数据和表格。

{"id" : "eew7-9yf2", "name" : "Student Loan Complaints", "averageRating" : 0, "createdAt" : 1434385453, "description" : "Each week we send thousands of consumers' complaints about financial products and services to companies for response. Complaints are listed in the database after the company responds or after they’ve had the complaint for 15 calendar days, whichever comes first.<br><br>\r\n\r\nWe publish the consumer’s description of what happened if the consumer opts to share it and after taking steps to remove personal information. See our <a href=\"http://files.consumerfinance.gov/a/assets/201503_cfpb_Narrative-Scrubbing-Standard.pdf\">Scrubbing Standard</a> for more details<br><br>\r\n\r\nWe don’t verify all the facts alleged in these complaints, but we take steps to confirm a commercial relationship. We may remove complaints if they don’t meet all of the publication criteria. Data is refreshed nightly.<br><br>\r\n\r\n<a href=\"http://www.consumerfinance.gov/complaintdatabase/\">More about the Consumer Complaint Database</a> | <a href=\"http://www.consumerfinance.gov/complaint/data-use/\">How we use complaint data</a> | <a href=\"http://www.consumerfinance.gov/complaintdatabase/technical-documentation/\">Technical documentation</a>", "displayType" : "table", "downloadCount" : 1461, "hideFromCatalog" : false, "hideFromDataJson" : false, "indexUpdatedAt" : 1520460881, "moderationStatus" : true, "modifyingViewUid" : "s6ew-h6mp", "newBackend" : false, "numberOfComments" : 0, "oid" : 22199210, "provenance" : "official", "publicationAppendEnabled" : false, "publicationDate" : 1467818298, "publicationGroup" : 2819740, "publicationStage" : "published", "rowsUpdatedAt" : 1520454464, "rowsUpdatedBy" : "pjxg-ve4m", "tableId" : 11756201, "totalTimesRated" : 0, "viewCount" : 4630, "viewLastModified" : 1456271502, "viewType" : "tabular", "grants" : [ {  "inherited" : true, "type" : "viewer", "flags" : [ "public" ]} ], "metadata" : {  "rdfSubject" : "0", "richRendererConfigs" : {    "fatRow" : {      "columns" : [{"styles" : {"width" : "27%"        },        "rows" : [ {"fields" : [ { "tableColumnId" : 28249505, "type" : "columnLabel"}, { "tableColumnId" : 28249505, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249497, "type" : "columnLabel"}, { "tableColumnId" : 28249497, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249498, "type" : "columnLabel"}, { "tableColumnId" : 28249498, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249499, "type" : "columnLabel"}, { "tableColumnId" : 28249499, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249500, "type" : "columnLabel"}, { "tableColumnId" : 28249500, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249502, "type" : "columnLabel"}, { "tableColumnId" : 28249502, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249503, "type" : "columnLabel"}, { "tableColumnId" : 28249503, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249504, "type" : "columnLabel"}, { "tableColumnId" : 28249504, "type" : "columnData"}] }]}, {        "styles" : {"width" : "40%"        },        "rows" : [ {"fields" : [ { "tableColumnId" : 28249493, "type" : "columnLabel"}, { "tableColumnId" : 28249493, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249495, "type" : "columnLabel"}, { "tableColumnId" : 28249495, "type" : "columnData"}] }]}, {        "styles" : {"width" : "30%"        },        "rows" : [ {"fields" : [ { "tableColumnId" : 28249508, "type" : "columnLabel"}, { "tableColumnId" : 28249508, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249507, "type" : "columnLabel"}, { "tableColumnId" : 28249507, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249509, "type" : "columnLabel"}, { "tableColumnId" : 28249509, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249510, "type" : "columnLabel"}, { "tableColumnId" : 28249510, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249511, "type" : "columnLabel"}, { "tableColumnId" : 28249511, "type" : "columnData"} ]},{"fields" : [ { "tableColumnId" : 28249492, "type" : "columnLabel"}, { "tableColumnId" : 28249492, "type" : "columnData"}] }]      } ]    }  }, "availableDisplayTypes" : [ "table", "fatrow", "page" ], "renderTypeConfig" : {    "visible" : {      "table" : true    }  }}, "owner" : {  "id" : "dfzt-mv86", "displayName" : "CFPB Administrator", "screenName" : "CFPB Administrator", "type" : "interactive", "flags" : [ "organizationMember" ]}},, "rights" : [ "read" ], "tableAuthor" : {  "id" : "pjxg-ve4m", "displayName" : "Shannon Files", "screenName" : "Shannon Files", "type" : "interactive", "flags" : [ "organizationMember" ]}},





create table complex5 (
id STRING,
name STRING,
averageRating FLOAT,
createdAt FLOAT,
description STRING,
displayType STRING,
downloadCount INT,
hideFromCatalog BOOLEAN,
hideFromDataJson BOOLEAN,
indexUpdatedAt FLOAT,
moderationStatus BOOLEAN,
newBackend BOOLEAN,
numberOfComments INT,
oid INT,
provenance STRING,
publicationAppendEnabled BOOLEAN,
publicationDate FLOAT,
publicationGroup INT,
publicationStage STRING,
rowClass STRING,
rowsUpdatedAt FLOAT,
rowsUpdatedBy STRING,
tableId INT,
totalTimesRated INT,
viewCount INT,
viewLastModified FLOAT,
viewType STRING,
grants ARRAY<MAP<STRING, STRING>>,
metadata STRUCT<rdfSubject:STRING, richRendererConfigs:STRUCT<fatRow:STRUCT<columns:ARRAY<STRUCT<styles:MAP<STRING,STRING>,rows:ARRAY<MAP<STRING,ARRAY<STRUCT<tableColumnId:INT,type:String>>>>>>>> , rowLabel:STRING, availableDisplayTypes: ARRAY<STRING>, renderTypeConfig:MAP<STRING, MAP<STRING, BOOLEAN>>>,
owner STRUCT<id:STRING, displayName:STRING, screenName:STRING, type:STRING, flags:ARRAY<STRING>>,
rights ARRAY<STRING>,
tableAuthor MAP<STRING, STRING>
)ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe';
4

2 回答 2

2

ROWS是保留字

您始终可以转义保留字

`rows`:ARRAY 

或者添加一个允许字段重命名的不同 SerDe

于 2018-03-10T03:37:55.810 回答
1

有一个JIRA,已在Hive 0.13.0版本中修复。根据发布

引用标识符的默认行为已更改。现在在语言级别,反引号(`)中指定的任何列名都按字面意思处理。这与引用标识符的标准 sql 行为一致。在反引号字符串中使用双反引号进行转义。

启用带引号的标识符

在文件中将hive.support.quoted.identifiers配置参数设置为以启用 SQL 列名中的带引号的标识符。对于,有效值为和。columnhive-site.xmlHive 0.13nonecolumn

set hive.support.quoted.identifiers = column 

例如

在以下示例中,x+ya?b是新表的有效列名。

CREATE TABLE test (`x+y` String, `a?b` String); 
于 2018-03-10T04:56:29.623 回答