FreedomOnce
FreedomOnce

Reputation: 31

How to create linked tables in Amazon Athena?

everyone! I have some problems with creating linked tables in Athena. When I add primary or foreign key to my sql query there is an error.

CREATE EXTERNAL TABLE `organization`( 
  `id` string PRIMARY KEY COMMENT 'from deserializer', 
  `version` int COMMENT 'from deserializer', 
  `timestamp` string COMMENT 'from deserializer', 
  `tzOffset` string COMMENT 'from deserializer')
ROW FORMAT SERDE 
  'org.openx.data.jsonserde.JsonSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.mapred.TextInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
  's3://test/test/'

CREATE EXTERNAL TABLE `users`( 
      `routinename` string COMMENT 'from deserializer', 
      `eventType` string COMMENT 'from deserializer', 
      FOREIGN KEY (organizationId) REFERENCES organization (id) COMMENT 'from deserializer')
    ROW FORMAT SERDE 
      'org.openx.data.jsonserde.JsonSerDe' 
    STORED AS INPUTFORMAT 
      'org.apache.hadoop.mapred.TextInputFormat' 
    OUTPUTFORMAT 
      'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
    LOCATION
      's3://test/test1/'

Can you help me?

Upvotes: 1

Views: 4170

Answers (1)

Theo
Theo

Reputation: 132952

There is no such thing as primary or foreign keys in Athena. Here is the documentation for what features Athena supports when creating a table: https://docs.aws.amazon.com/athena/latest/ug/create-table.html

Primary and foreign keys are used by RDBMSs for ensuring constraints – for example to ensure you don't insert rows with duplicate IDs, or remove rows in related tables. These are not as relevant in a system like Athena where there are no inserts or updates.

Upvotes: 3

Related Questions