Skip to content

Instantly share code, notes, and snippets.

@javisantana
javisantana / license.txt
Last active Jun 1, 2021
NMEA parser in java which does not suck
View license.txt
this software is under the terms of MIT license: http://opensource.org/licenses/MIT
View gps.java
package hardware;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
View clickhouse_query_log_replicas.md

When you a clickhouse cluster and you run queries on all the replicas it's not easy to get all the queries ran. I use system.query_log all the time to check timings, errors and so on.

So what I do is create a global query_log:

:) create view query_log_all on cluster my_cluster as select * from remote('10.0.0.1,10.0.0.2', 'system.query_log')

So I can inspect queries in all the replicas with a single query:

View generating_scripts_from_clickhouse.md

Sometimes you have to move data from one table to a different one. You usually use

insert into target select * from source

This works but have several problems:

  1. materialized columns are not properly copied
  2. it's slow
View link
View til_clickhouse_replicas_status.md

Clickhouse has a pretty good endpoint /replicas_status which gives information about the, guess what, replication status. When you are working on a cluster in which you use replication to increase the amount of QPS you usually have a load balancer before, something like this:

                                 +--------------+
                                 |              |
                       +-------->+  clickhouse  |
                       |         |              |
                       |         +--------------+
                       |
View union_all_and_push_down_in_clickhouse.md

Looks like filters are pushed down when filtering an "UNION ALL". Also an example on how to use EXPLAIN in clickhouse and a different view of seeing what is going on with the traces, this lines show how much data clickhouse is reading:

Selected 1 parts by date, 1 parts by key, 2 marks by primary key, 2 marks to read from 1 ranges
Reading approx. 16384 rows with 1 streams

The example

@javisantana
javisantana / til_dynamic_joinget.md
Last active Nov 6, 2020
how to generate a map data structure dynamically in clickhouse
View til_dynamic_joinget.md

Clickhouse has a powerful feature, JOIN engines, that allows to prepare a table to be joined with better performance that a regular table (MergeTree, Log...). It also allows to use joinGet to get table values using a key.

Somtimes you don't have a JOIN table but you'd like to use something with the joinGet performance. Unfortunately you can't use joinGet with something created on the fly (well, you could create a temporally join table but you need several SQL queries).

So there is a way to do that, using transform:

with (
  select (groupArray(key), groupArray(value)) from my_table
) as key_value
@javisantana
javisantana / compile clickhouse on mojave.md
Last active Mar 11, 2020
compile clickhouse on mojave
View compile clickhouse on mojave.md

clickhouse on osx

These are the steps I followed to compile clickhouse on OSX mojave (10.4.3). These might not be the best way to make it compile on OSX, my knowledge about C++ and build tooling is really limited but they do the work.

clickhouse sha-1: 2ad4df1d6a

compile command (apply the patch below before running cmake)

@javisantana
javisantana / summing_merge_tree.sql
Created Jan 17, 2020
SummingMergetree multiple keys in nested maps
View summing_merge_tree.sql
MacBook-Pro-de-javi.local :) create table multiple_keys (tmp Int32, testMap Nested (a Int32, bKey Int32, value Int32)) Engine=SummingMergeTree() order by (tmp);
CREATE TABLE multiple_keys
(
`tmp` Int32,
`testMap` Nested(
a Int32,
bKey Int32,
value Int32)
)