Skip to content

Default values don’t work when using JSONEachRow format w/o specifying column names #75

Closed

Description

@Har01d

The code:

DROP TABLE IF EXISTS test_table;

CREATE TABLE test_table (
  a String,
  b Date,
  c DEFAULT sipHash64(a),
  d MATERIALIZED sipHash64(a)
) ENGINE = MergeTree(b, a, 8192);

INSERT INTO test_table (a, b) values ('1', '2016-01-01');

INSERT INTO test_table (a, b) FORMAT JSONEachRow {"a":"2","b":"2016-01-02"}

INSERT INTO test_table values ('3', '2016-01-03'); -- throws an error

INSERT INTO test_table FORMAT JSONEachRow {"a":"4","b":"2016-01-04"} -- doesn’t throw an error

SELECT *, d FROM test_table ORDER BY a;

The result:

┌─a─┬──────────b─┬────────────────────c─┬────────────────────d─┐
│ 1 │ 2016-01-01 │  5003827105613308882 │  5003827105613308882 │
│ 2 │ 2016-01-02 │ 11449545338359147399 │ 11449545338359147399 │
│ 4 │ 2016-01-04 │                    0 │  3672830208859661989 │
└───┴────────────┴──────────────────────┴──────────────────────┘

The expected result:

┌─a─┬──────────b─┬────────────────────c─┬────────────────────d─┐
│ 1 │ 2016-01-01 │  5003827105613308882 │  5003827105613308882 │
│ 2 │ 2016-01-02 │ 11449545338359147399 │ 11449545338359147399 │
│ 4 │ 2016-01-04 │  3672830208859661989 │  3672830208859661989 │
└───┴────────────┴──────────────────────┴──────────────────────┘

Activity

  1. changed the title [-]Default values don’t work when using JSONEachRow format[/-] [+]Default values don’t work when using JSONEachRow format w/o specifying column names[/+] on Aug 17, 2016
  2. alexey-milovidov commented on Aug 17, 2016

    @alexey-milovidov
    Member

    It is known (documented) issue.
    https://clickhouse.yandex/reference_en.html#JSONEachRow

    N.B. when using JSONEachRow format, complex default values are not supported, so when omitting a column its value will be zeros or empty string depending on its type.

    The reason is that complex default values need expression evaluation, but data formats currently are independent of expressions interpreters.

    But we already have many requests to implement this functionality, so we have to do it.

  3. filimonov commented on Nov 17, 2017

    @filimonov
    Contributor

    +1 to fix

  4. kolsys commented on Jul 31, 2018

    @kolsys
    Contributor

    +1 to fix

  5. myy2829 commented on Sep 26, 2018

    @myy2829

    +1 to fix

  6. 4ertus2 commented on Dec 11, 2018

    @4ertus2
    Contributor

    Works in master. It needs insert_sample_with_metadata to be set.

    DROP TABLE IF EXISTS test_table;
    
    CREATE TABLE test_table (
      a String,
      b Date,
      c DEFAULT sipHash64(a),
      d MATERIALIZED sipHash64(a)
    ) ENGINE = MergeTree(b, a, 8192);
    
    SET insert_sample_with_metadata=1;
    INSERT INTO test_table FORMAT JSONEachRow {"a":"4","b":"2016-01-04"}
    SELECT a, c, d, sipHash64(a) FROM test_table ORDER BY a;
    
    4       5406800756778728304     5406800756778728304     5406800756778728304
    

    P.S. There's a mistake in sample. 3672830208859661989 == sipHash64('3'), not sipHash64('4').

  7. self-assigned this
    on Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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