user3123372
user3123372

Reputation: 744

does hive allows column name as "rows"?

I know every hive version has some reserve keywords, which cant be used as a column name.

But the problem is my data comes from a json, and my column name are according to the json values.

And I cant modify the data off course. Is there any alternative??

here is one row of the sample data and the 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';

Upvotes: 0

Views: 581

Answers (2)

Gyanendra Dwivedi
Gyanendra Dwivedi

Reputation: 5547

There was a JIRA, which was fixed in Hive 0.13.0 version. As per the release

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.

Enabling Quoted Identifiers

Set the hive.support.quoted.identifiers configuration parameter to column in the hive-site.xml file to enable quoted identifiers in SQL column names. For Hive 0.13, the valid values are none and column.

set hive.support.quoted.identifiers = column 

e.g.

In the following example, x+y and a?b are valid column names for a new table.

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

Upvotes: 1

OneCricketeer
OneCricketeer

Reputation: 191874

ROWS is a reserved word

You can always escape reserved words

`rows`:ARRAY 

Alternatively add a different SerDe that allows field renaming

Upvotes: 2

Related Questions