配置单元是否允许列名称为 "rows"?

does hive allows column name as "rows"?

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

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

当然我不能修改数据。 有别的办法吗??

这里是一行示例数据和 table。

{"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';

ROWS is a reserved word

你总是可以转义保留字

`rows`:ARRAY 

或者add a different SerDe that allows field renaming

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

The default behavior for quoted identifiers has been changed. Now at the language level any Column Name that is specified within back-ticks(`) is treated literally. This is inline with standard sql behavior for quoted identifiers. Within back-tick strings use double back-ticks to escape.

启用带引号的标识符

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

set hive.support.quoted.identifiers = column 

例如

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

CREATE TABLE test (`x+y` String, `a?b` String);