Getting Started

In addition to Athena query costs, the text analytics UDF incurs usage costs from AWS Lambda and Amazon Comprehend. The amount you pay is a factor of the total number of records and characters that you process with the UDF. For more information, see AWS Lambda pricing and Amazon Comprehend pricing. Please limit the number of rows that are passed to the UDF.

Follow the instructions and screenshots below to get started with the text analysis UDF.

  • Open the AWS Management Console for Athena in the same region you are using the lab
  • Switch to the V2EngineWorkGroup

  • Run your first text analytics query

    Enter the following query into the SQL editor
      
    USING EXTERNAL FUNCTION detect_sentiment(text_col VARCHAR, lang VARCHAR) RETURNS VARCHAR LAMBDA 'textanalytics-udf' 
    SELECT detect_sentiment('I am very happy with this product', 'en') as sentiment;
    You get a simple POSITIVE result. Now try again, varying the input text—try something less positive to see how the returned sentiment value changes.
      
    USING EXTERNAL FUNCTION detect_sentiment(text_col VARCHAR, lang VARCHAR) RETURNS VARCHAR LAMBDA 'textanalytics-udf'
    SELECT detect_sentiment('I am extremely frustrated with this seller.', 'en') as sentiment;
    The above query yields a NEGATIVE sentiment. Let us now take a deeper look at how the sentiment is derived. For that, let us use the detect_sentiment_all function call which will give us the confidence scores for each potential sentiment value.
      
    USING EXTERNAL FUNCTION detect_sentiment_all(text_col VARCHAR, lang VARCHAR) RETURNS VARCHAR LAMBDA 'textanalytics-udf'
    SELECT detect_sentiment_all('I am very happy with this product', 'en') as sentiment;
    The result is a JSON string with the sentiment and confidence scores.
      
    {
    	"sentiment": "POSITIVE",
    	"sentimentScore": {
    		"positive": 0.99981767,
    		"negative": 5.033472E-5,
    		"neutral": 7.5651784E-5,
    		"mixed": 5.64253E-5
    	}
    }
    Now that you have some familiarity running the UDF functions, let us move on to our next labs that cover some real-world usecases of text analysis.