Clickhouse create jdbc engine table? - clickhouse

CREATE TABLE jdbc_table
ENGINE = JDBC('jdbc:mysql://192.168.10.16:4307/?user=root&password=root', 'test', 'test')
this statement gets error
Syntax error: failed at position 114 (end of query):
CREATE TABLE jdbc_table ENGINE =
JDBC('jdbc:mysql://192.168.10.16:4307/?user=root&password=root',
'test', 'test')
Expected one of: AS, SETTINGS, TTL, PARTITION BY, PRIMARY KEY, ORDER
BY, SAMPLE BY
I don't know why.

Documentation is incorrect. Create table needs a columns list (e.g. (A String, B UInt32)).
create table jdbc.category engine
= JDBC('datasource://postgresql', 'public', 'category')
as select * from jdbc('datasource://postgresql', 'public', 'category');
or
create table jdbc.category(A String, B UInt32)
engine = JDBC('datasource://postgresql', 'public', 'category')

Related

clickhouse alter MATERIALIZED VIEW add column

env: Clikchouse version:22.3.3.44; Database engine: atomic
I have a raw table and mv, schema like this:
CREATE TABLE IF NOT EXISTS test.Income_Raw on cluster '{cluster}' (
Id Int64,
DateNum Date,
Cnt Int64,
LoadTime DateTime
) ENGINE==MergeTree
PARTITION BY toYYYYMMDD(LoadTime)
ORDER BY (Id, DateNum);
CREATE MATERIALIZED VIEW test.Income_MV on cluster '{cluster}'
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/{shard}/{database}/{table}', '{replica}')
PARTITION BY toYYYYMM(DateNum)
ORDER BY (Id, DateNum)
TTL DateNum+ INTERVAL 100 DAY
AS SELECT
DateNum,
Id,
argMaxState(Cnt, LoadTime) as Cnt ,
maxState( LoadTime) as latest_loadtime
FROM test.Income_Raw
GROUP BY Id, DataNum;
now I want to add a column named 'price' to raw table and mv,
so I run sql step by step like below:
// first I alter raw table
1. alter table test.Income_Raw on cluster '{cluster}' add column Price Int32
// below sqls, I run to alter MV
2. detach test.Income_MV on cluster '{cluster}'
3. alter test.`.inner_id.{uuid}` on cluster '{cluster}' add column Price Int32
// step 4, basically I just use 'attach' replace 'create' and add 'Price' to select query
4. attach MATERIALIZED VIEW test.Income_MV on cluster '{cluster}'
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/{shard}/{database}/{table}', '{replica}')
PARTITION BY toYYYYMM(DateNum)
ORDER BY (Id, DateNum)
TTL DateNum+ INTERVAL 100 DAY
AS SELECT
DateNum,
Id,
Price,
argMaxState(Cnt, LoadTime) as Cnt ,
maxState( LoadTime) as latest_loadtime
FROM test.Income_Raw
GROUP BY Id, DataNum, Price;
but at step 4, I met error like this
Code: 80. DB::Exception: Incorrect ATTACH TABLE query for Atomic database engine. Use one of the following queries instead:
1. ATTACH TABLE Income_MV;
2. CREATE TABLE Income_MV <table definition>;
3. ATTACH TABLE Income_MV FROM '/path/to/data/' <table definition>;
4. ATTACH TABLE Income_MVUUID '<uuid>' <table definition>;. (INCORRECT_QUERY) (version 22.3.3.44 (official build))
these sqls I runned is I followed from below references.
https://kb.altinity.com/altinity-kb-schema-design/materialized-views/
Clickhouse altering materialized view's select
so my question is, how to modify mv select query, which step I was wrong?
I figure out that just need:
prepare: use explicit target table instead inner table for MV
1 alter MV target table
2 drop MV
3 re-create MV with new query

dictGetString fails on DDL created dictionary in clickhouse

Attempting to follow the instructions for creating a dictionary using DDL:
-- source table
create table brands (
id UInt64,
brand String
)
ENGINE = ReplacingMergeTree(id)
partition by tuple()
order by id;
-- some data
insert into brands values (1, 'cool'), (2, 'neat'), (3, 'fun');
-- dictionary references source table
CREATE DICTIONARY IF NOT EXISTS brand_dict (
id UInt64,
brand String
)
PRIMARY KEY id
SOURCE(CLICKHOUSE(
host 'localhost'
port 9000
user 'default'
password ''
db 'default'
table 'brands'
))
LIFETIME(MIN 1 MAX 10)
LAYOUT(FLAT())
-- looks good:
show dictionaries;
-- no work
-- Code: 36. DB::Exception: Received from localhost:9000. DB::Exception: external dictionary 'brand_dict' not found.
select dictGetString('brand_dict', 'id', toUInt64(1));
Gives DB::Exception: external dictionary 'brand_dict' not found.
I haven't tried with XML config yet, so not sure if it's DDL specific, or if there's something I'm doing wrong there.
such dictionaries require database specified
dictGetString('DATABASE.brand_dict'
UPD: Starting from 21.4 Functions dictGet, dictHas use current database name if it is not specified for dictionaries created with DDL

How to change a table to partition table with DBMS_REDEFINITION but no primary key in current table

How to convert a non-partition table (no primary key) to partitioned table? Someone says I can use rowid, but I can not find any sample from Oracle doc.
My oracle is 12C release 1, it did not contain the new feature Using the MODIFY clause of ALTER TABLE to convert online to a partitioned table.
Please provide a sample if you can.
"Someone says can use rowed, but I can not find any sample from oracle doc"
I think the option you are looking for is the DBMS_REDEFINITION.START_REDEF_TABLE parameter options_flag.
Like this
start_redef_table (
uname => 'your_schema'
, orig_table => 'your_current_table'
, int_table => 'your_interim_table'
, options_flag => dbms_redefinition.cons_use_rowid
);
Find out more

Partitions are still showing in hive even though they are dropped for an external table

I have an external table in hive partitioned by year, month, day. So I dropped one partition but I still see it in show partitions.
>use test_raw_tables;
>show partitions test1_raw;
[year=2016/month=01/day=01]
[year=2017/month=03/day=24]
> alter table test1_raw drop partition (year=2016, month=01, day=01);
> refresh test1_raw;
> show partitions test1_raw;
[year=2016/month=01/day=01]
[year=2017/month=03/day=24] ---Still see the dropped partition here----
> msck repair table test1_raw;
> show partitions test1_raw;
[year=2016/month=01/day=01]
[year=2017/month=03/day=24] ---Still see the dropped partition here----
Running from impala with hive as engine.
describe test1_raw
col_name,data_type,comment ('amount_hold', 'int', '') ('id', 'int', '') ('transaction_id', 'string', '') ('recipient_id', 'string', '') ('year', 'string', '') ('month', 'string', '') ('day', 'string', '') ('', None, None) ('# Partition Information', None, None) ('# col_name ', 'data_type ', 'comment ') ('', None, None) ('year', 'string', '') ('month', 'string', '') ('day', 'string', '')
location 'hdfs://localhost/sys/datalake/testing/test1_raw'
What is the problem here?
The data in hdfs is deleted for that partition after dropping it. Cannot figure out the issue.
In your Table defination Column Year, Month and Day are in String format.
Pls try with '2016', '01' and '01'.
I used below code and it works.
alter table test1_raw drop partition (year='2016', month='01', day='01');
Not that it matters anymore but you changed a definition of a table. You didn't change the data. Hive is unique in that it will let you define schema on read, altering the definition is just altering the definition it's not changing the data only the table definition. You can have multiple tables sit on top of the same data without issues, it doesn't mean a table definition change in one affects the other. (Well I'm talking about On READ anyways...)

Exporting data from query results

I am using MS SQL server 2014.
I have a table-valued function
ALTER FUNCTION [dbo].[Resultsaddresssearch](#addressLine nvarchar, #locality nvarchar, #adminDistrict nvarchar, #postalCode nvarchar, #countryRegion nvarchar)
RETURNS TABLE (
[Name] nvarchar NULL,
[Point] [geography] NULL,
[BoundingBox] [geography] NULL
) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [xtest2].[addresssearch.UserDefinedFunctions].[GeocodeTVF]
that I use this query
SELECT * FROM dbo.Resultsaddresssearch('999 NE 10th%', '', '', '', 'USA');
The results I wish to export to a premaded csv that is addy,csv. When I used the export manager, I selected the sql native client 11 as source. Then select Flat File as destination. I enter the query from above and hit next and I get this error:
- Column "Point": Source data type "204" was not found in the data type mapping file.
- Column "BoundingBox": Source data type "204" was not found in the data type mapping file.
Thanks
It is not what I what but creating an sql query
Insert into [dbo].[ConversionofGeotest2]
Select * from Geotest2 ('62 NE 10th Ave', '', '', '97211', 'US');

Resources