use-cases/aws-lambda-redshift-event-driven-etl/LambdaSetupRedshiftObjects.py [22:55]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            DROP MATERIALIZED VIEW IF EXISTS  nyc_yellow_taxi_volume_analysis;
            DROP TABLE IF EXISTS nyc_yellow_taxi;
            '''
    response = invoke_redshift_data_api_lambda(lambda_arn, redshift_cluster_id, redshift_database, redshift_user, sql_text, sns_topic_arn)
    logger.info(response)
    cfnresponse.send(event, context, cfnresponse.SUCCESS, {'Data': 'Delete complete'})
  else:
    sql_text = '''
            CREATE TABLE IF NOT EXISTS nyc_yellow_taxi
            (pickup_date        DATE
            , pickup_datetime  TIMESTAMP
            , dropoff_datetime TIMESTAMP
            , ratecode         SMALLINT
            , passenger_count  SMALLINT
            , trip_distance    FLOAT4
            , fare_amount      FLOAT4
            , total_amount     FLOAT4
            , payment_type     SMALLINT
            , vendorid         VARCHAR(20))
            SORTKEY(pickup_date);

            DROP MATERIALIZED VIEW IF EXISTS  nyc_yellow_taxi_volume_analysis;

            CREATE MATERIALIZED VIEW nyc_yellow_taxi_volume_analysis
            AS
            SELECT
              DATE_TRUNC('mon',pickup_date) pickup_month
            , ROUND(AVG(trip_distance),2) avg_distance
            , ROUND(AVG(fare_amount),2) avg_fare
            , COUNT(1) total_trips
            , SUM(trip_distance) total_distance_per_month
            , SUM(fare_amount) total_fare_per_month
            FROM nyc_yellow_taxi
            GROUP BY 1;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



use-cases/aws-lambda-redshift-event-driven-etl/event-driven-redshift-pipeline.yaml [344:377]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                      DROP MATERIALIZED VIEW IF EXISTS  nyc_yellow_taxi_volume_analysis;
                      DROP TABLE IF EXISTS nyc_yellow_taxi;
                      '''
              response = invoke_redshift_data_api_lambda(lambda_arn, redshift_cluster_id, redshift_database, redshift_user, sql_text, sns_topic_arn)
              logger.info(response)
              cfnresponse.send(event, context, cfnresponse.SUCCESS, {'Data': 'Delete complete'})
            else:
              sql_text = '''
                      CREATE TABLE IF NOT EXISTS nyc_yellow_taxi
                      (pickup_date        DATE
                      , pickup_datetime  TIMESTAMP
                      , dropoff_datetime TIMESTAMP
                      , ratecode         SMALLINT
                      , passenger_count  SMALLINT
                      , trip_distance    FLOAT4
                      , fare_amount      FLOAT4
                      , total_amount     FLOAT4
                      , payment_type     SMALLINT
                      , vendorid         VARCHAR(20))
                      SORTKEY(pickup_date);

                      DROP MATERIALIZED VIEW IF EXISTS  nyc_yellow_taxi_volume_analysis;

                      CREATE MATERIALIZED VIEW nyc_yellow_taxi_volume_analysis
                      AS
                      SELECT
                        DATE_TRUNC('mon',pickup_date) pickup_month
                      , ROUND(AVG(trip_distance),2) avg_distance
                      , ROUND(AVG(fare_amount),2) avg_fare
                      , COUNT(1) total_trips
                      , SUM(trip_distance) total_distance_per_month
                      , SUM(fare_amount) total_fare_per_month
                      FROM nyc_yellow_taxi
                      GROUP BY 1;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



