Skip to content

Cannot parse Nan (but NULL in TabSeparated format) #700

Closed

Description

@egorlitvinenko

:) CREATE TABLE hello_world.hello_world_table(f1 Nullable(String),f2 Nullable(Float64),f3 Nullable(Int64),f4 Nullable(DateTime),f5 Nullable(Float64)) ENGINE = TinyLog;

CREATE TABLE hello_world.hello_world_table
(
f1 Nullable(String),
f2 Nullable(Float64),
f3 Nullable(Int64),
f4 Nullable(DateTime),
f5 Nullable(Float64)
) ENGINE = TinyLog

Ok.

:) INSERT INTO hello_world.hello_world_table(f2,f5,f3,f1,f4) FORMAT TabSeparated NULL 7.81651003481571E8 1886081650 zlwwqlbkvrksdt NULL

INSERT INTO hello_world.hello_world_table (f2, f5, f3, f1, f4) FORMAT TabSeparated

Exception on client:
Code: 27. DB::Exception: Cannot parse NaN.: (at row 1)

Row 1:
Column 0, name: f2, type: Nullable(Float64), parsed text: "N"ERROR

Connecting to localhost:9000.
Connected to ClickHouse server version 1.1.54189.

FORMAT TabSeparated is default and hardcoded in Clickhouse Jdbc.

Activity

  1. ztlpn commented on Apr 15, 2017

    @ztlpn
    Contributor

    You can use \N for NULL values.

  2. egorlitvinenko commented on Apr 15, 2017

    @egorlitvinenko
    Author

    Do you have an example?

    :) INSERT INTO hello_world.hello_world_table(f2,f5,f3,f1,f4) FORMAT TabSeparated \N 7.81651003481571E8 1886081650 zlwwqlbkvrksdt \N;

    INSERT INTO hello_world.hello_world_table (f2, f5, f3, f1, f4) FORMAT TabSeparated

    Exception on client:
    Code: 27. DB::Exception: Cannot parse input: expected \t before: 7.81651003481571E8 1886081650 zlwwqlbkvrksdt \N;: (at row 1)

    Row 1:
    Column 0, name: f2, type: Nullable(Float64), parsed text: "N"
    ERROR: garbage after Nullable(Float64): " 7.8165100"

    Connecting to localhost:9000.
    Connected to ClickHouse server version 1.1.54189.

    I checked tabs again and:

    :) INSERT INTO hello_world.hello_world_table(f2,f5,f3,f1,f4) FORMAT TabSeparated \N 7.81651003481571E8 1886081650 zlwwqlbkvrksdt \N;

    INSERT INTO hello_world.hello_world_table (f2, f5, f3, f1, f4) FORMAT TabSeparated

    Exception on client:
    Code: 27. DB::Exception: Cannot parse input: expected \n before: ;: (at row 1)

    Row 1:
    Column 0, name: f2, type: Nullable(Float64), parsed text: "N"
    Column 1, name: f5, type: Nullable(Float64), parsed text: "7.81651003481571E8"
    Column 2, name: f3, type: Nullable(Int64), parsed text: "1886081650"
    Column 3, name: f1, type: Nullable(String), parsed text: "zlwwqlbkvrksdt"
    Column 4, name: f4, type: Nullable(DateTime), parsed text: "N"
    ERROR: garbage after Nullable(DateTime): ";"

    Connecting to localhost:9000.
    Connected to ClickHouse server version 1.1.54189.

    :)

  3. egorlitvinenko commented on Apr 15, 2017

    @egorlitvinenko
    Author

    Example data:

    vjebywyypgqorighfaw,,898999574,,3.008874029012975E8
    tjqevznxclm,,2079703005,,1.1591825521454709E9
    aawethajnahzxgxzzdu,,1461070703,,7.682462476872058E8
    feubrhhqaja,,1078610460,,8.908589890974745E8
    hnjurnrlpcjxfa,,469686467,,6.0313867905135885E7
    bqzqaphgvjj,,1133548469,,1.046040289828672E8
    zcpozsgfctj,,949290936,,1.710776620861809E9
    
    

    What choises are available to import it?

  4. ztlpn commented on Apr 15, 2017

    @ztlpn
    Contributor

    Sure:

    :) create table t1(f1 Nullable(String),f2 Nullable(Float64),f3 Nullable(Int64),f4 Nullable(DateTime),f5 Nullable(Float64)) engine = TinyLog;
    
    CREATE TABLE t1
    (
        f1 Nullable(String),
        f2 Nullable(Float64),
        f3 Nullable(Int64),
        f4 Nullable(DateTime),
        f5 Nullable(Float64)
    ) ENGINE = TinyLog
    
    Ok.
    
    0 rows in set. Elapsed: 0.015 sec.
    
    :) insert into t1(f2,f5,f3,f1,f4) FORMAT TSV \N 7.8     1111    aaa     \N
    
    INSERT INTO t1 (f2, f5, f3, f1, f4) FORMAT TSV
    
    Ok.
    
    1 rows in set. Elapsed: 0.001 sec.
    
    :)
    

    The problem is with ';' character: because the remainder of the query after 'FORMAT TSV' is fed into the TabSeparated parser as is, the semicolon is parsed as part of the data, not as the end of query.

  5. ztlpn commented on Apr 15, 2017

    @ztlpn
    Contributor

    What choises are available to import it?

    CSV parser does not recognize empty string as a NULL value, so you will have to manually insert '\N' where you want NULLs to be.

  6. egorlitvinenko commented on Apr 15, 2017

    @egorlitvinenko
    Author

    @ztlpn thanks for your help :)

  7. alexey-milovidov commented on Apr 20, 2017

    @alexey-milovidov
    Member

    We should implement empty_as_null, null_string_as_null and similar options.

  8. added a commit that references this issue on Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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