0

An attempt of creating view in Athena managed by CloudFormation fails if an sql query, that is a view contains more than one string.

I'm using this and this topics as an example. The problem is when I'm trying to query my view, I`m getting an error

GENERIC_INTERNAL_ERROR: Invalid JSON bytes for [simple type, class io.trino.spi.connector.ConnectorViewDefinition]

  SomeView:
    Type: AWS::Glue::Table
    Properties:
      CatalogId: !Ref CatalogId
      DatabaseName: !Ref Database
      TableInput:
        Name: v_some_table
        TableType: VIRTUAL_VIEW
        Parameters: 
          presto_view: true
        StorageDescriptor: 
          SerdeInfo:
            SerializationLibrary: org.openx.data.jsonserde.JsonSerDe
        ViewOriginalText: !Sub
          - '/* Presto View: ${View} */'
          - 
            View: 
              Fn::Base64: !Sub |
                {
                  "catalog": "awsdatacatalog",
                  "schema": "${Database}",
                  "columns": [
                    {
                      "name": "portal",
                      "type": "varchar"
                    },
                    {
                      "name": "trafficsource",
                      "type": "varchar"
                    },
                    {
                      "name": "month",
                      "type": "bigint"
                    },
                    {
                      "name": "paybackperiod",
                      "type": "bigint"
                    },
                    {
                      "name": "lifeday",
                      "type": "bigint"
                    },
                    {
                      "name": "roasbenchmark",
                      "type": "varchar"
                    }
                    
                  ],
                  "originalSql": "SELECT 
                      's' as portal, 
                      't' as trafficsource, 
                      100 as month, 
                      101 as paybackperiod, 
                      100 as lifeday, 
                      'r' as roasbenchmark"
                }

The problem is due to my OriginalText SQL query is multiline. Single-line query works fine:

"originalSql": "SELECT 's' as portal, t' as trafficsource, 100 as month, 101 as paybackperiod, 100 as lifeday, 'r' as roasbenchmark"

I`v tried to handle with multi-line, according to this but all my attemps had failed with the same error:

"originalSql": "SELECT 
                      's' as portal, 
                      't' as trafficsource, 
                      100 as month, 
                      101 as paybackperiod, 
                      100 as lifeday, 
                      'r' as roasbenchmark"

"originalSql": | 
    "SELECT 
                      's' as portal, 
                      't' as trafficsource, 
                      100 as month, 
                      101 as paybackperiod, 
                      100 as lifeday, 
                      'r' as roasbenchmark"

"originalSql": |
    SELECT 
                  's' as portal, 
                  't' as trafficsource, 
                  100 as month, 
                  101 as paybackperiod, 
                  100 as lifeday, 
                  'r' as roasbenchmark

"originalSql": >
    SELECT 
                  's' as portal, 
                  't' as trafficsource, 
                  100 as month, 
                  101 as paybackperiod, 
                  100 as lifeday, 
                  'r' as roasbenchmark

Any ideas oh how to handle with multi-line SQL queries?

user1443993
  • 371
  • 4
  • 10

0 Answers0