Tanmay
Tanmay

Reputation: 393

AWS Athena Fails to Run any WHERE clause on table

I have set-up a data lake in AWS S3 and created a table in it using Athena. Here's the CREATE TABLE statement I used:

CREATE EXTERNAL TABLE `controllers`(
  `commandkey` varchar(40), 
  `commandvalue` varchar(5), 
  `container` varchar(15), 
  `containername` varchar(15), 
  `controllerid` varchar(5), 
  `cpupercent` float, 
  `deviceid` varchar(5), 
  `diskpercent` float, 
  `epoch` timestamp, 
  `error` map<varchar(20),array<varchar(10)>>, 
  `errorvalue` map<varchar(15),varchar(20)>, 
  `exceptioninfo` varchar(50), 
  `exceptionname` varchar(8), 
  `funcname` varchar(20), 
  `jouleboxcontrollerid` varchar(5), 
  `key` varchar(40), 
  `level` varchar(8), 
  `linenumber` varchar(5), 
  `linkquality` float, 
  `logtype` varchar(20), 
  `memorypercent` float, 
  `mode` varchar(10), 
  `module` varchar(20), 
  `networkstrength` float, 
  `param` varchar(15), 
  `rc` int, 
  `requesttopic` varchar(50), 
  `response` varchar(5), 
  `responsetopic` varchar(50), 
  `restarttime` timestamp, 
  `rid` varchar(15), 
  `shifttype` char(1), 
  `siteid` varchar(8), 
  `source` varchar(15), 
  `startedat` timestamp, 
  `status` varchar(5), 
  `topic` varchar(50), 
  `ts` timestamp, 
  `type` varchar(15), 
  `val` varchar(20), 
  `value` varchar(5))
ROW FORMAT SERDE 
  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
  's3://controller-logs.smartjoules.org/raw'
TBLPROPERTIES (
  'classification'='PARQUET'
)

Whenever I try to run a simple SELECT query with a WHERE clause like:

SELECT AVG(networkstrength) 
FROM controllers
WHERE deviceid="123"

it fails throwing the error: SYNTAX_ERROR: line 2:21: Column '123' cannot be resolved

I'm not sure whether its a problem with the CREATE TABLE statement or data ingetion/storage or something completely different.

Upvotes: 2

Views: 3092

Answers (2)

Emerson
Emerson

Reputation: 1166

surrounding a string with " makes it think that you are referring to a column name and not a literal value. Use ' for your string

Upvotes: 2

Ilya Kisil
Ilya Kisil

Reputation: 2658

You have a problem with a query syntax. Use single quotes when you refer to a string values, because double quotes refer to a column name in your table

SELECT AVG(networkstrength) 
FROM controllers
WHERE deviceid='123'

Upvotes: 7

Related Questions