Skip to content

ch10 - sparksql- Inserting into tables query not working Cannot safely cast 'count': string to bigint #68

@shanmugavel04

Description

@shanmugavel04

Query in the book:
INSERT INTO partitioned_flights
PARTITION (DEST_COUNTRY_NAME="UNITED STATES")
SELECT count, ORIGIN_COUNTRY_NAME FROM flights
WHERE DEST_COUNTRY_NAME='UNITED STATES'
LIMIT 12
In Spark 3.0, The above query returns the below error in SQL statement: AnalysisException: Cannot write incompatible data to table 'default.partitioned_flights':

  • Cannot safely cast 'count': string to bigint
    so, modified the query as below to cast the count column as an integer.
    INSERT INTO partitioned_flights
    PARTITION (DEST_COUNTRY_NAME = "UNITED STATES")
    SELECT ORIGIN_COUNTRY_NAME, cast(count as int) count1 FROM flights
    WHERE DEST_COUNTRY_NAME = "UNITED STATES"
    LIMIT 12
    could you please check on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions