Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not detect SimpleAggregateFunction DataType #69

Closed
mbtolou opened this issue Mar 15, 2021 · 6 comments
Closed

Not detect SimpleAggregateFunction DataType #69

mbtolou opened this issue Mar 15, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@mbtolou
Copy link

mbtolou commented Mar 15, 2021

Bulk insert not detect datatype of column :

create table test.data_test
(
ts DATETIME,
id VARCHAR, 
v0 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
v1 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
v2 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
v3 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
p0 SimpleAggregateFunction(anyLast,Nullable(VARCHAR))
) ENGINE=AggregatingMergeTree 
PARTITION BY toStartOfQuarter(ts) 
ORDER BY (ts,id);

exception like this :

One or more errors occurred. (Unknown type: SimpleAggregateFunction(anyLast, Nullable(Decimal(12, 0))))

@DarkWanderer
Copy link
Owner

Hi. See #51 and docs - you cannot insert directly to table with aggregate function (using any client, not just this one).

I recommend creating a "virtual" table (with Null engine)

CREATE TABLE test.data_test_insert  
(
   ts DateTime,
  id VARCHAR,
  v0 Float64,
  v0 Float64,
  v0 Float64,
  v0 Float64,
  p0 VARCHAR
)
ENGINE Null;
FROM test.data_test_insert

and a "Material view" (trigger) which will insert data from the "virtual" table to your actual table:

CREATE MATERIALIZED VIEW test.data_test_mv TO test.data_test AS SELECT 
   ts,
  id,
  anyLastState(v0),
  anyLastState(v1),
  anyLastState(v2),
  anyLastState(v3),
  anyLastState(p0)
FROM test.data_test_insert

This way, you can bulk insert into the "virtual" table and the data will automatically flow into regular one

@mbtolou
Copy link
Author

mbtolou commented Mar 16, 2021

but i test with dbeaver.

insert record successfully done in dbeaver .

@DarkWanderer
Copy link
Owner

Can you share the insert statement you used?

@mbtolou
Copy link
Author

mbtolou commented Mar 16, 2021

drop table if exists  test.data_test;

create table test.data_test
(
ts DATETIME,
id VARCHAR, 
v0 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
v1 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
v2 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
v3 SimpleAggregateFunction(anyLast,Nullable(Float64)), 
p0 SimpleAggregateFunction(anyLast,Nullable(VARCHAR))
) ENGINE=AggregatingMergeTree 
PARTITION BY toStartOfQuarter(ts) 
ORDER BY (ts,id);

insert into test.data_test values('2019-01-01 00:00:00','id1',null,null,null,null,null);
insert into test.data_test values('2019-01-01 00:00:00','id2',1,1,1,1,'str1');
insert into test.data_test values('2019-01-01 00:00:00','id2',3,3,3,3,'str3');
insert into test.data_test(ts,id,v0,v1,v2) values('2019-01-01 00:00:00','id2',4,2,4);
insert into test.data_test(ts,id,v0,v1,v2) values('2019-01-01 00:00:00','id2',4,4,4);

select * from test.data_test;

select * from test.data_test final;



@DarkWanderer
Copy link
Owner

Hm, I didn't realize SimpleAggregateFunction behaves differently from AggregateFunction for insertion. I can add support in that case

@DarkWanderer DarkWanderer self-assigned this Mar 16, 2021
@DarkWanderer DarkWanderer added the enhancement New feature or request label Mar 16, 2021
DarkWanderer added a commit that referenced this issue Mar 16, 2021
* Adding support for reading/writing SimpleAggregateFunctionType #69

* Added SELECT test
@DarkWanderer
Copy link
Owner

Will be in next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants