diff --git a/go.mod b/go.mod index 17687db20e..7634b2ecbb 100644 --- a/go.mod +++ b/go.mod @@ -105,7 +105,7 @@ require ( yunion.io/x/ovsdb v0.0.0-20200526071744-27bf0940cbc7 yunion.io/x/pkg v1.0.1-0.20220630095420-9925accd7c5e yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e - yunion.io/x/sqlchemy v1.1.2-0.20220701050442-4a04411dc606 + yunion.io/x/sqlchemy v1.1.2-0.20220701113246-498f1b8c1941 yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 ) @@ -117,7 +117,7 @@ require ( github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect github.com/Azure/go-autorest/logger v0.1.0 // indirect github.com/Azure/go-autorest/tracing v0.5.0 // indirect - github.com/ClickHouse/clickhouse-go/v2 v2.1.0 // indirect + github.com/ClickHouse/clickhouse-go v1.5.4 // indirect github.com/DataDog/dd-trace-go v0.6.1 // indirect github.com/DataDog/zstd v1.3.4 // indirect github.com/Masterminds/goutils v1.1.0 // indirect @@ -143,6 +143,7 @@ require ( github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect github.com/bradfitz/iter v0.0.0-20140124041915-454541ec3da2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 // indirect github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -173,6 +174,7 @@ require ( github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect github.com/google/btree v1.0.0 // indirect + github.com/google/go-cmp v0.5.7 // indirect github.com/google/go-querystring v1.0.0 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/google/uuid v1.3.0 // indirect @@ -212,7 +214,6 @@ require ( github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492 // indirect github.com/opentracing/opentracing-go v1.0.2 // indirect github.com/openzipkin/zipkin-go-opentracing v0.3.4 // indirect - github.com/paulmach/orb v0.7.1 // indirect github.com/philhofer/fwd v1.0.0 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pkg/term v1.0.0 // indirect @@ -225,7 +226,6 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect github.com/satori/go.uuid v1.2.0 // indirect - github.com/shopspring/decimal v1.3.1 // indirect github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect @@ -240,8 +240,6 @@ require ( github.com/yusufpapurcu/wmi v1.2.2 // indirect go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect go.opencensus.io v0.22.4 // indirect - go.opentelemetry.io/otel v1.7.0 // indirect - go.opentelemetry.io/otel/trace v1.7.0 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect diff --git a/go.sum b/go.sum index 26862ef6ac..3eb82da523 100644 --- a/go.sum +++ b/go.sum @@ -71,9 +71,8 @@ github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VY github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0= github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= -github.com/ClickHouse/clickhouse-go/v2 v2.1.0 h1:X53a5FzRna9TLGGYm1A7T+3kEnrfEYl15BNsL6sw81s= -github.com/ClickHouse/clickhouse-go/v2 v2.1.0/go.mod h1:nOBMOlMUGQJ2eb6PtECHYldbEHmDJFzfIrtaDXMjrb4= github.com/DataDog/dd-trace-go v0.6.1 h1:nsZ2lohbSw1CKtfNRu3wPh1jFirv6XSz8vqNpuIYWbM= github.com/DataDog/dd-trace-go v0.6.1/go.mod h1:SmQTTcC37XMyEm75HV0AWiZIYxDiaNhRi49zorIpW+o= github.com/DataDog/zstd v1.3.4 h1:LAGHkXuvC6yky+C2CUG2tD7w8QlrUwpue8XwIh0X4AY= @@ -99,7 +98,6 @@ github.com/Shopify/sarama v1.20.0 h1:wAMHhl1lGRlobeoV/xOKpbqD2OQsOvY4A/vIOGroIe8 github.com/Shopify/sarama v1.20.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM= @@ -169,6 +167,7 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y= github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA= +github.com/bkaradzic/go-lz4 v1.0.0 h1:RXc4wYsyz985CkXXeX04y4VnZFGG8Rd43pRaHsOXAKk= github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= @@ -189,6 +188,7 @@ github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/o github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 h1:F1EaeKL/ta07PY/k9Os/UFtwERei2/XzGemhpGnBKNg= github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/coredns/coredns v1.3.0 h1:Ubjr8ZrOpEj95/A9dqQqQAG2k5DWEFdg2ZB3tUXuULA= @@ -272,8 +272,6 @@ github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= @@ -389,7 +387,6 @@ github.com/googollee/go-socket.io v0.0.0-20181214084611-0ad7206c347a/go.mod h1:f github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U= github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= @@ -539,7 +536,6 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -573,9 +569,6 @@ github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go-opentracing v0.3.4 h1:x/pBv/5VJNWkcHF1G9xqhug8Iw7X1y1zOMzDmyuvP2g= github.com/openzipkin/zipkin-go-opentracing v0.3.4/go.mod h1:js2AbwmHW0YD9DwIw2JhQWmbfFi/UnWyYwdVhqbCDOE= -github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU= -github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A= -github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= @@ -637,12 +630,8 @@ github.com/serialx/hashring v0.0.0-20180504054112-49a4782e9908 h1:RRpyb4kheanCQV github.com/serialx/hashring v0.0.0-20180504054112-49a4782e9908/go.mod h1:/yeG0My1xr/u+HZrFQ1tOQQQQrOawfyMUH13ai5brBc= github.com/sevlyar/go-daemon v0.1.5 h1:Zy/6jLbM8CfqJ4x4RPr7MJlSKt90f00kNM1D401C+Qk= github.com/sevlyar/go-daemon v0.1.5/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE= -github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= -github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= -github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= @@ -675,7 +664,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/syncthing/syncthing v0.14.48-rc.4/go.mod h1:nw3siZwHPA6M8iSfjDCWQ402eqvEIasMQOE8nFOxy7M= @@ -735,10 +723,6 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= -go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= -go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o= -go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= @@ -885,7 +869,6 @@ golang.org/x/sys v0.0.0-20191003212358-c178f38b412c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191220220014-0732a990476f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1152,7 +1135,7 @@ yunion.io/x/pkg v1.0.1-0.20220630095420-9925accd7c5e h1:p/Cb7z6gyJbZKnGMeOPL3pTm yunion.io/x/pkg v1.0.1-0.20220630095420-9925accd7c5e/go.mod h1:nYOMflWG1wQC6301rGVglQva9bYbJxHThEJUxRAgMFc= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo= yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo= -yunion.io/x/sqlchemy v1.1.2-0.20220701050442-4a04411dc606 h1:pJxI4+XTxna3e+gcGfuX2KNEBPrTqFXGcFLhqiEPqzA= -yunion.io/x/sqlchemy v1.1.2-0.20220701050442-4a04411dc606/go.mod h1:OoWrAW7qeaJmLlgMtwwMrxV10+91HLngPq0cZFtj9ig= +yunion.io/x/sqlchemy v1.1.2-0.20220701113246-498f1b8c1941 h1:ZSopMA3JfDGhjGw8fBzvxJeu9vAkdwk1tstMmkLfm40= +yunion.io/x/sqlchemy v1.1.2-0.20220701113246-498f1b8c1941/go.mod h1:xXVfJLIxxTRTnPEaVIIoRZXqWyO8+takIOYhc+zO5KE= yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6 h1:WuWXhY3DvhdRTzWCJ/kwt3Ss6KIq7+KqJwb+esvNGwU= yunion.io/x/structarg v0.0.0-20220312084958-9c6c79c7d1c6/go.mod h1:EP6NSv2C0zzqBDTKumv8hPWLb3XvgMZDHQRfyuOrQng= diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/.gitignore b/vendor/github.com/ClickHouse/clickhouse-go/.gitignore similarity index 93% rename from vendor/github.com/ClickHouse/clickhouse-go/v2/.gitignore rename to vendor/github.com/ClickHouse/clickhouse-go/.gitignore index 7f0f42e822..940583ffc4 100644 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/.gitignore +++ b/vendor/github.com/ClickHouse/clickhouse-go/.gitignore @@ -2,7 +2,6 @@ *.o *.a *.so -*.cap # Folders _obj @@ -26,5 +25,4 @@ _testmain.go *.prof coverage.txt -.idea/** -dev/* \ No newline at end of file +.idea/** \ No newline at end of file diff --git a/vendor/github.com/ClickHouse/clickhouse-go/.travis.yml b/vendor/github.com/ClickHouse/clickhouse-go/.travis.yml new file mode 100644 index 0000000000..52b61d7cd0 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/.travis.yml @@ -0,0 +1,20 @@ +sudo: required +language: go +go: + - 1.15.x + - 1.16.x +go_import_path: github.com/ClickHouse/clickhouse-go +services: + - docker +install: + - export GO111MODULE="on" + - go mod vendor + +before_install: + - docker --version + - docker-compose --version + - docker-compose up -d +script: + - ./go.test.sh +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/CONTRIBUTING.md b/vendor/github.com/ClickHouse/clickhouse-go/CONTRIBUTING.md similarity index 100% rename from vendor/github.com/ClickHouse/clickhouse-go/v2/CONTRIBUTING.md rename to vendor/github.com/ClickHouse/clickhouse-go/CONTRIBUTING.md diff --git a/vendor/github.com/ClickHouse/clickhouse-go/LICENSE b/vendor/github.com/ClickHouse/clickhouse-go/LICENSE new file mode 100644 index 0000000000..a860ed2071 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017-2020 Kirill Shvakov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/ClickHouse/clickhouse-go/Makefile b/vendor/github.com/ClickHouse/clickhouse-go/Makefile new file mode 100644 index 0000000000..813b31965d --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/Makefile @@ -0,0 +1,8 @@ +test: + go install -race -v + go test -i -v + go test -race -timeout 30s -v . + +coverage: + go test -coverprofile=coverage.out -v . + go tool cover -html=coverage.out diff --git a/vendor/github.com/ClickHouse/clickhouse-go/README.md b/vendor/github.com/ClickHouse/clickhouse-go/README.md new file mode 100644 index 0000000000..c438013002 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/README.md @@ -0,0 +1,307 @@ +# ClickHouse [![Build Status](https://travis-ci.org/ClickHouse/clickhouse-go.svg?branch=master)](https://travis-ci.org/ClickHouse/clickhouse-go) [![Go Report Card](https://goreportcard.com/badge/github.com/ClickHouse/clickhouse-go)](https://goreportcard.com/report/github.com/ClickHouse/clickhouse-go) [![codecov](https://codecov.io/gh/ClickHouse/clickhouse-go/branch/master/graph/badge.svg)](https://codecov.io/gh/ClickHouse/clickhouse-go) + +Golang SQL database driver for [Yandex ClickHouse](https://clickhouse.yandex/) + +## Key features + +* Uses native ClickHouse TCP client-server protocol +* Compatibility with `database/sql` +* Round Robin load-balancing +* Bulk write support : `begin->prepare->(in loop exec)->commit` +* LZ4 compression support (default is pure go lz4 or switch to use cgo lz4 by turning clz4 build tags on) +* External Tables support + +## DSN + +* username/password - auth credentials +* database - select the current default database +* read_timeout/write_timeout - timeout in second +* no_delay - disable/enable the Nagle Algorithm for tcp socket (default is 'true' - disable) +* alt_hosts - comma-separated list of single address hosts for load-balancing +* connection_open_strategy - random/in_order (default random). + * random - choose a random server from the set + * in_order - first live server is chosen in specified order + * time_random - choose random (based on the current time) server from the set. This option differs from `random` because randomness is based on the current time rather than on the number of previous connections. +* block_size - maximum rows in block (default is 1000000). If the rows are larger, the data will be split into several blocks to send to the server. If one block was sent to the server, the data would be persisted on the server disk, and we can't roll back the transaction. So always keep in mind that the batch size is no larger than the block_size if you want an atomic batch insert. +* pool_size - the maximum amount of preallocated byte chunks used in queries (default is 100). Decrease this if you experience memory problems at the expense of more GC pressure and vice versa. +* debug - enable debug output (boolean value) +* compress - enable lz4 compression (integer value, default is '0') +* check_connection_liveness - on supported platforms non-secure connections retrieved from the connection pool are checked in beginTx() for liveness before using them. If the check fails, the respective connection is marked as bad and the query retried with another connection. (boolean value, default is 'true') + +SSL/TLS parameters: + +* secure - establish secure connection (default is false) +* skip_verify - skip certificate verification (default is false) +* tls_config - name of a TLS config with client certificates, registered using `clickhouse.RegisterTLSConfig()`; implies secure to be true, unless explicitly specified + +Example: + +```sh +tcp://host1:9000?username=user&password=qwerty&database=clicks&read_timeout=10&write_timeout=20&alt_hosts=host2:9000,host3:9000 +``` + +## Supported data types + +* UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64 +* Float32, Float64 +* String +* FixedString(N) +* Date +* DateTime +* IPv4 +* IPv6 +* Enum +* UUID +* Nullable(T) +* [Array(T)](https://clickhouse.yandex/reference_en.html#Array(T)) [godoc](https://godoc.org/github.com/ClickHouse/clickhouse-go#Array) +* Array(Nullable(T)) +* Tuple(...T) + +## TODO + +* Support other compression methods(zstd ...) + +## Install + +```sh +go get -u github.com/ClickHouse/clickhouse-go +``` + +## Examples + +```go +package main + +import ( + "database/sql" + "fmt" + "log" + "time" + + "github.com/ClickHouse/clickhouse-go" +) + +func main() { + connect, err := sql.Open("clickhouse", "tcp://127.0.0.1:9000?debug=true") + if err != nil { + log.Fatal(err) + } + if err := connect.Ping(); err != nil { + if exception, ok := err.(*clickhouse.Exception); ok { + fmt.Printf("[%d] %s \n%s\n", exception.Code, exception.Message, exception.StackTrace) + } else { + fmt.Println(err) + } + return + } + + _, err = connect.Exec(` + CREATE TABLE IF NOT EXISTS example ( + country_code FixedString(2), + os_id UInt8, + browser_id UInt8, + categories Array(Int16), + action_day Date, + action_time DateTime + ) engine=Memory + `) + + if err != nil { + log.Fatal(err) + } + var ( + tx, _ = connect.Begin() + stmt, _ = tx.Prepare("INSERT INTO example (country_code, os_id, browser_id, categories, action_day, action_time) VALUES (?, ?, ?, ?, ?, ?)") + ) + defer stmt.Close() + + for i := 0; i < 100; i++ { + if _, err := stmt.Exec( + "RU", + 10+i, + 100+i, + clickhouse.Array([]int16{1, 2, 3}), + time.Now(), + time.Now(), + ); err != nil { + log.Fatal(err) + } + } + + if err := tx.Commit(); err != nil { + log.Fatal(err) + } + + rows, err := connect.Query("SELECT country_code, os_id, browser_id, categories, action_day, action_time FROM example") + if err != nil { + log.Fatal(err) + } + defer rows.Close() + + for rows.Next() { + var ( + country string + os, browser uint8 + categories []int16 + actionDay, actionTime time.Time + ) + if err := rows.Scan(&country, &os, &browser, &categories, &actionDay, &actionTime); err != nil { + log.Fatal(err) + } + log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_day: %s, action_time: %s", country, os, browser, categories, actionDay, actionTime) + } + + if err := rows.Err(); err != nil { + log.Fatal(err) + } + + if _, err := connect.Exec("DROP TABLE example"); err != nil { + log.Fatal(err) + } +} +``` + +### Use [sqlx](https://github.com/jmoiron/sqlx) + +```go +package main + +import ( + "log" + "time" + + "github.com/jmoiron/sqlx" + _ "github.com/ClickHouse/clickhouse-go" +) + +func main() { + connect, err := sqlx.Open("clickhouse", "tcp://127.0.0.1:9000?debug=true") + if err != nil { + log.Fatal(err) + } + var items []struct { + CountryCode string `db:"country_code"` + OsID uint8 `db:"os_id"` + BrowserID uint8 `db:"browser_id"` + Categories []int16 `db:"categories"` + ActionTime time.Time `db:"action_time"` + } + + if err := connect.Select(&items, "SELECT country_code, os_id, browser_id, categories, action_time FROM example"); err != nil { + log.Fatal(err) + } + + for _, item := range items { + log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_time: %s", item.CountryCode, item.OsID, item.BrowserID, item.Categories, item.ActionTime) + } +} +``` + +### External tables support + +```go +package main + +import ( + "database/sql" + "database/sql/driver" + "fmt" + "github.com/ClickHouse/clickhouse-go/lib/column" + "log" + "time" + + "github.com/ClickHouse/clickhouse-go" +) + +func main() { + connect, err := sql.Open("clickhouse", "tcp://127.0.0.1:9000?debug=true") + if err != nil { + log.Fatal(err) + } + if err := connect.Ping(); err != nil { + if exception, ok := err.(*clickhouse.Exception); ok { + fmt.Printf("[%d] %s \n%s\n", exception.Code, exception.Message, exception.StackTrace) + } else { + fmt.Println(err) + } + return + } + + _, err = connect.Exec(` + CREATE TABLE IF NOT EXISTS example ( + country_code FixedString(2), + os_id UInt8, + browser_id UInt8, + categories Array(Int16), + action_day Date, + action_time DateTime + ) engine=Memory + `) + + if err != nil { + log.Fatal(err) + } + var ( + tx, _ = connect.Begin() + stmt, _ = tx.Prepare("INSERT INTO example (country_code, os_id, browser_id, categories, action_day, action_time) VALUES (?, ?, ?, ?, ?, ?)") + ) + defer stmt.Close() + + for i := 0; i < 100; i++ { + if _, err := stmt.Exec( + "RU", + 10+i, + 100+i, + clickhouse.Array([]int16{1, 2, 3}), + time.Now(), + time.Now(), + ); err != nil { + log.Fatal(err) + } + } + + if err := tx.Commit(); err != nil { + log.Fatal(err) + } + + col, err := column.Factory("country_code", "String", nil) + if err != nil { + log.Fatal(err) + } + countriesExternalTable := clickhouse.ExternalTable{ + Name: "countries", + Values: [][]driver.Value{ + {"RU"}, + }, + Columns: []column.Column{col}, + } + + rows, err := connect.Query("SELECT country_code, os_id, browser_id, categories, action_day, action_time "+ + "FROM example WHERE country_code IN ?", countriesExternalTable) + if err != nil { + log.Fatal(err) + } + defer rows.Close() + + for rows.Next() { + var ( + country string + os, browser uint8 + categories []int16 + actionDay, actionTime time.Time + ) + if err := rows.Scan(&country, &os, &browser, &categories, &actionDay, &actionTime); err != nil { + log.Fatal(err) + } + log.Printf("country: %s, os: %d, browser: %d, categories: %v, action_day: %s, action_time: %s", country, os, browser, categories, actionDay, actionTime) + } + + if err := rows.Err(); err != nil { + log.Fatal(err) + } + + if _, err := connect.Exec("DROP TABLE example"); err != nil { + log.Fatal(err) + } +} +``` diff --git a/vendor/github.com/ClickHouse/clickhouse-go/array.go b/vendor/github.com/ClickHouse/clickhouse-go/array.go new file mode 100644 index 0000000000..997b8ab6a5 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/array.go @@ -0,0 +1,21 @@ +package clickhouse + +import ( + "time" +) + +func Array(v interface{}) interface{} { + return v +} + +func ArrayFixedString(len int, v interface{}) interface{} { + return v +} + +func ArrayDate(v []time.Time) interface{} { + return v +} + +func ArrayDateTime(v []time.Time) interface{} { + return v +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/bootstrap.go b/vendor/github.com/ClickHouse/clickhouse-go/bootstrap.go new file mode 100644 index 0000000000..3e11e66e78 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/bootstrap.go @@ -0,0 +1,255 @@ +package clickhouse + +import ( + "bufio" + "database/sql" + "database/sql/driver" + "fmt" + "io" + "log" + "net/url" + "os" + "strconv" + "strings" + "sync" + "sync/atomic" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" + "github.com/ClickHouse/clickhouse-go/lib/data" + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +const ( + // DefaultDatabase when connecting to ClickHouse + DefaultDatabase = "default" + // DefaultUsername when connecting to ClickHouse + DefaultUsername = "default" + // DefaultConnTimeout when connecting to ClickHouse + DefaultConnTimeout = 5 * time.Second + // DefaultReadTimeout when reading query results + DefaultReadTimeout = time.Minute + // DefaultWriteTimeout when sending queries + DefaultWriteTimeout = time.Minute +) + +var ( + unixtime int64 + logOutput io.Writer = os.Stdout + hostname, _ = os.Hostname() + poolInit sync.Once +) + +func init() { + sql.Register("clickhouse", &bootstrap{}) + go func() { + for tick := time.Tick(time.Second); ; { + select { + case <-tick: + atomic.AddInt64(&unixtime, int64(time.Second)) + } + } + }() +} + +func now() time.Time { + return time.Unix(0, atomic.LoadInt64(&unixtime)) +} + +type bootstrap struct{} + +func (d *bootstrap) Open(dsn string) (driver.Conn, error) { + return Open(dsn) +} + +// SetLogOutput allows to change output of the default logger +func SetLogOutput(output io.Writer) { + logOutput = output +} + +// Open the connection +func Open(dsn string) (driver.Conn, error) { + clickhouse, err := open(dsn) + if err != nil { + return nil, err + } + + return clickhouse, err +} + +func open(dsn string) (*clickhouse, error) { + url, err := url.Parse(dsn) + if err != nil { + return nil, err + } + var ( + hosts = []string{url.Host} + query = url.Query() + secure = false + skipVerify = false + tlsConfigName = query.Get("tls_config") + noDelay = true + compress = false + database = query.Get("database") + username = query.Get("username") + password = query.Get("password") + blockSize = 1000000 + connTimeout = DefaultConnTimeout + readTimeout = DefaultReadTimeout + writeTimeout = DefaultWriteTimeout + connOpenStrategy = connOpenRandom + checkConnLiveness = true + ) + if len(database) == 0 { + database = DefaultDatabase + } + if len(username) == 0 { + username = DefaultUsername + } + if v, err := strconv.ParseBool(query.Get("no_delay")); err == nil { + noDelay = v + } + tlsConfig := getTLSConfigClone(tlsConfigName) + if tlsConfigName != "" && tlsConfig == nil { + return nil, fmt.Errorf("invalid tls_config - no config registered under name %s", tlsConfigName) + } + secure = tlsConfig != nil + if v, err := strconv.ParseBool(query.Get("secure")); err == nil { + secure = v + } + if v, err := strconv.ParseBool(query.Get("skip_verify")); err == nil { + skipVerify = v + } + if duration, err := strconv.ParseFloat(query.Get("timeout"), 64); err == nil { + connTimeout = time.Duration(duration * float64(time.Second)) + } + if duration, err := strconv.ParseFloat(query.Get("read_timeout"), 64); err == nil { + readTimeout = time.Duration(duration * float64(time.Second)) + } + if duration, err := strconv.ParseFloat(query.Get("write_timeout"), 64); err == nil { + writeTimeout = time.Duration(duration * float64(time.Second)) + } + if size, err := strconv.ParseInt(query.Get("block_size"), 10, 64); err == nil { + blockSize = int(size) + } + if altHosts := strings.Split(query.Get("alt_hosts"), ","); len(altHosts) != 0 { + for _, host := range altHosts { + if len(host) != 0 { + hosts = append(hosts, host) + } + } + } + switch query.Get("connection_open_strategy") { + case "random": + connOpenStrategy = connOpenRandom + case "in_order": + connOpenStrategy = connOpenInOrder + case "time_random": + connOpenStrategy = connOpenTimeRandom + } + + settings, err := makeQuerySettings(query) + if err != nil { + return nil, err + } + + if v, err := strconv.ParseBool(query.Get("compress")); err == nil { + compress = v + } + + if v, err := strconv.ParseBool(query.Get("check_connection_liveness")); err == nil { + checkConnLiveness = v + } + if secure { + // There is no way to check the liveness of a secure connection, as long as there is no access to raw TCP net.Conn + checkConnLiveness = false + } + + var ( + ch = clickhouse{ + logf: func(string, ...interface{}) {}, + settings: settings, + compress: compress, + blockSize: blockSize, + checkConnLiveness: checkConnLiveness, + ServerInfo: data.ServerInfo{ + Timezone: time.Local, + }, + } + logger = log.New(logOutput, "[clickhouse]", 0) + ) + if debug, err := strconv.ParseBool(url.Query().Get("debug")); err == nil && debug { + ch.logf = logger.Printf + } + ch.logf("host(s)=%s, database=%s, username=%s", + strings.Join(hosts, ", "), + database, + username, + ) + options := connOptions{ + secure: secure, + tlsConfig: tlsConfig, + skipVerify: skipVerify, + hosts: hosts, + connTimeout: connTimeout, + readTimeout: readTimeout, + writeTimeout: writeTimeout, + noDelay: noDelay, + openStrategy: connOpenStrategy, + logf: ch.logf, + } + if ch.conn, err = dial(options); err != nil { + return nil, err + } + logger.SetPrefix(fmt.Sprintf("[clickhouse][connect=%d]", ch.conn.ident)) + ch.buffer = bufio.NewWriter(ch.conn) + + ch.decoder = binary.NewDecoderWithCompress(ch.conn) + ch.encoder = binary.NewEncoderWithCompress(ch.buffer) + + if err := ch.hello(database, username, password); err != nil { + ch.conn.Close() + return nil, err + } + return &ch, nil +} + +func (ch *clickhouse) hello(database, username, password string) error { + ch.logf("[hello] -> %s", ch.ClientInfo) + { + ch.encoder.Uvarint(protocol.ClientHello) + if err := ch.ClientInfo.Write(ch.encoder); err != nil { + return err + } + { + ch.encoder.String(database) + ch.encoder.String(username) + ch.encoder.String(password) + } + if err := ch.encoder.Flush(); err != nil { + return err + } + + } + { + packet, err := ch.decoder.Uvarint() + if err != nil { + return err + } + switch packet { + case protocol.ServerException: + return ch.exception() + case protocol.ServerHello: + if err := ch.ServerInfo.Read(ch.decoder); err != nil { + return err + } + case protocol.ServerEndOfStream: + ch.logf("[bootstrap] <- end of stream") + return nil + default: + return fmt.Errorf("[hello] unexpected packet [%d] from server", packet) + } + } + ch.logf("[hello] <- %s", ch.ServerInfo) + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse.go new file mode 100644 index 0000000000..babc89358d --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse.go @@ -0,0 +1,354 @@ +package clickhouse + +import ( + "bufio" + "context" + "database/sql" + "database/sql/driver" + "errors" + "fmt" + "net" + "reflect" + "regexp" + "sync" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" + "github.com/ClickHouse/clickhouse-go/lib/column" + "github.com/ClickHouse/clickhouse-go/lib/data" + "github.com/ClickHouse/clickhouse-go/lib/protocol" + "github.com/ClickHouse/clickhouse-go/lib/types" +) + +type ( + Date = types.Date + DateTime = types.DateTime + UUID = types.UUID +) + +type ExternalTable struct { + Name string + Values [][]driver.Value + Columns []column.Column +} + +var ( + ErrInsertInNotBatchMode = errors.New("insert statement supported only in the batch mode (use begin/commit)") + ErrLimitDataRequestInTx = errors.New("data request has already been prepared in transaction") +) + +var ( + splitInsertRe = regexp.MustCompile(`(?i)\sVALUES\s*\(`) +) + +type logger func(format string, v ...interface{}) + +type clickhouse struct { + sync.Mutex + data.ServerInfo + data.ClientInfo + logf logger + conn *connect + block *data.Block + buffer *bufio.Writer + decoder *binary.Decoder + encoder *binary.Encoder + settings *querySettings + compress bool + blockSize int + inTransaction bool + checkConnLiveness bool +} + +func (ch *clickhouse) Prepare(query string) (driver.Stmt, error) { + return ch.prepareContext(context.Background(), query) +} + +func (ch *clickhouse) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { + return ch.prepareContext(ctx, query) +} + +func (ch *clickhouse) prepareContext(ctx context.Context, query string) (driver.Stmt, error) { + ch.logf("[prepare] %s", query) + switch { + case ch.conn.closed: + return nil, driver.ErrBadConn + case ch.block != nil: + return nil, ErrLimitDataRequestInTx + case isInsert(query): + if !ch.inTransaction { + return nil, ErrInsertInNotBatchMode + } + return ch.insert(ctx, query) + } + return &stmt{ + ch: ch, + query: query, + numInput: numInput(query), + }, nil +} + +func (ch *clickhouse) insert(ctx context.Context, query string) (_ driver.Stmt, err error) { + if err := ch.sendQuery(ctx, splitInsertRe.Split(query, -1)[0]+" VALUES ", nil); err != nil { + return nil, err + } + if ch.block, err = ch.readMeta(); err != nil { + return nil, err + } + return &stmt{ + ch: ch, + isInsert: true, + }, nil +} + +func (ch *clickhouse) Begin() (driver.Tx, error) { + return ch.beginTx(context.Background(), txOptions{}) +} + +func (ch *clickhouse) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { + return ch.beginTx(ctx, txOptions{ + Isolation: int(opts.Isolation), + ReadOnly: opts.ReadOnly, + }) +} + +type txOptions struct { + Isolation int + ReadOnly bool +} + +func (ch *clickhouse) beginTx(ctx context.Context, opts txOptions) (*clickhouse, error) { + ch.logf("[begin] tx=%t, data=%t", ch.inTransaction, ch.block != nil) + switch { + case ch.inTransaction: + return nil, sql.ErrTxDone + case ch.conn.closed: + return nil, driver.ErrBadConn + } + + // Perform a stale connection check. We only perform this check in beginTx, + // because database/sql retries driver.ErrBadConn only for first request, + // but beginTx doesn't perform any other network interaction. + if ch.checkConnLiveness { + if err := ch.conn.connCheck(); err != nil { + ch.logf("[begin] closing bad idle connection: %w", err) + ch.Close() + return ch, driver.ErrBadConn + } + } + + if finish := ch.watchCancel(ctx); finish != nil { + defer finish() + } + ch.block = nil + ch.inTransaction = true + return ch, nil +} + +func (ch *clickhouse) Commit() error { + ch.logf("[commit] tx=%t, data=%t", ch.inTransaction, ch.block != nil) + defer func() { + if ch.block != nil { + ch.block.Reset() + ch.block = nil + } + ch.inTransaction = false + }() + switch { + case !ch.inTransaction: + return sql.ErrTxDone + case ch.conn.closed: + return driver.ErrBadConn + } + if ch.block != nil { + if err := ch.writeBlock(ch.block, ""); err != nil { + return err + } + // Send empty block as marker of end of data. + if err := ch.writeBlock(&data.Block{}, ""); err != nil { + return err + } + if err := ch.encoder.Flush(); err != nil { + return err + } + return ch.process() + } + return nil +} + +func (ch *clickhouse) Rollback() error { + ch.logf("[rollback] tx=%t, data=%t", ch.inTransaction, ch.block != nil) + if !ch.inTransaction { + return sql.ErrTxDone + } + if ch.block != nil { + ch.block.Reset() + } + ch.block = nil + ch.buffer = nil + ch.inTransaction = false + return ch.conn.Close() +} + +func (ch *clickhouse) CheckNamedValue(nv *driver.NamedValue) error { + switch nv.Value.(type) { + case ExternalTable, column.IP, column.UUID: + return nil + case nil, []byte, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64, string, time.Time: + return nil + } + switch v := nv.Value.(type) { + case + []int, []int8, []int16, []int32, []int64, + []uint, []uint8, []uint16, []uint32, []uint64, + []float32, []float64, + []string: + return nil + case net.IP, *net.IP: + return nil + case driver.Valuer: + value, err := v.Value() + if err != nil { + return err + } + nv.Value = value + default: + switch value := reflect.ValueOf(nv.Value); value.Kind() { + case reflect.Slice: + return nil + case reflect.Bool: + nv.Value = uint8(0) + if value.Bool() { + nv.Value = uint8(1) + } + case reflect.Int8: + nv.Value = int8(value.Int()) + case reflect.Int16: + nv.Value = int16(value.Int()) + case reflect.Int32: + nv.Value = int32(value.Int()) + case reflect.Int64: + nv.Value = value.Int() + case reflect.Uint8: + nv.Value = uint8(value.Uint()) + case reflect.Uint16: + nv.Value = uint16(value.Uint()) + case reflect.Uint32: + nv.Value = uint32(value.Uint()) + case reflect.Uint64: + nv.Value = uint64(value.Uint()) + case reflect.Float32: + nv.Value = float32(value.Float()) + case reflect.Float64: + nv.Value = float64(value.Float()) + case reflect.String: + nv.Value = value.String() + } + } + return nil +} + +func (ch *clickhouse) Close() error { + ch.block = nil + return ch.conn.Close() +} + +func (ch *clickhouse) process() error { + packet, err := ch.decoder.Uvarint() + if err != nil { + return err + } + for { + switch packet { + case protocol.ServerPong: + ch.logf("[process] <- pong") + return nil + case protocol.ServerException: + ch.logf("[process] <- exception") + return ch.exception() + case protocol.ServerProgress: + progress, err := ch.progress() + if err != nil { + return err + } + ch.logf("[process] <- progress: rows=%d, bytes=%d, total rows=%d", + progress.rows, + progress.bytes, + progress.totalRows, + ) + case protocol.ServerProfileInfo: + profileInfo, err := ch.profileInfo() + if err != nil { + return err + } + ch.logf("[process] <- profiling: rows=%d, bytes=%d, blocks=%d", profileInfo.rows, profileInfo.bytes, profileInfo.blocks) + case protocol.ServerData: + block, err := ch.readBlock() + if err != nil { + return err + } + ch.logf("[process] <- data: packet=%d, columns=%d, rows=%d", packet, block.NumColumns, block.NumRows) + case protocol.ServerEndOfStream: + ch.logf("[process] <- end of stream") + return nil + default: + ch.conn.Close() + return fmt.Errorf("[process] unexpected packet [%d] from server", packet) + } + if packet, err = ch.decoder.Uvarint(); err != nil { + return err + } + } +} + +func (ch *clickhouse) cancel() error { + ch.logf("[cancel request]") + // even if we fail to write the cancel, we still need to close + err := ch.encoder.Uvarint(protocol.ClientCancel) + if err == nil { + err = ch.encoder.Flush() + } + // return the close error if there was one, otherwise return the write error + if cerr := ch.conn.Close(); cerr != nil { + return cerr + } + return err +} + +func (ch *clickhouse) watchCancel(ctx context.Context) func() { + if done := ctx.Done(); done != nil { + finished := make(chan struct{}) + go func() { + select { + case <-done: + ch.cancel() + finished <- struct{}{} + ch.logf("[cancel] <- done") + case <-finished: + ch.logf("[cancel] <- finished") + } + }() + return func() { + select { + case <-finished: + case finished <- struct{}{}: + } + } + } + return func() {} +} + +func (ch *clickhouse) ExecContext(ctx context.Context, query string, + args []driver.NamedValue) (driver.Result, error) { + finish := ch.watchCancel(ctx) + defer finish() + stmt, err := ch.PrepareContext(ctx, query) + if err != nil { + return nil, err + } + dargs := make([]driver.Value, len(args)) + for i, nv := range args { + dargs[i] = nv.Value + } + return stmt.Exec(dargs) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_exception.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_exception.go new file mode 100644 index 0000000000..2317d94377 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_exception.go @@ -0,0 +1,46 @@ +package clickhouse + +import ( + "fmt" + "strings" +) + +type Exception struct { + Code int32 + Name string + Message string + StackTrace string + nested error +} + +func (e *Exception) Error() string { + return fmt.Sprintf("code: %d, message: %s", e.Code, e.Message) +} + +func (ch *clickhouse) exception() error { + var ( + e Exception + err error + hasNested bool + ) + if e.Code, err = ch.decoder.Int32(); err != nil { + return err + } + if e.Name, err = ch.decoder.String(); err != nil { + return err + } + if e.Message, err = ch.decoder.String(); err != nil { + return err + } + e.Message = strings.TrimSpace(strings.TrimPrefix(e.Message, e.Name+":")) + if e.StackTrace, err = ch.decoder.String(); err != nil { + return err + } + if hasNested, err = ch.decoder.Bool(); err != nil { + return err + } + if hasNested { + e.nested = ch.exception() + } + return &e +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_ping.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_ping.go new file mode 100644 index 0000000000..9c6b50a2bf --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_ping.go @@ -0,0 +1,28 @@ +package clickhouse + +import ( + "context" + "database/sql/driver" + + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +func (ch *clickhouse) Ping(ctx context.Context) error { + return ch.ping(ctx) +} + +func (ch *clickhouse) ping(ctx context.Context) error { + if ch.conn.closed { + return driver.ErrBadConn + } + ch.logf("-> ping") + finish := ch.watchCancel(ctx) + defer finish() + if err := ch.encoder.Uvarint(protocol.ClientPing); err != nil { + return err + } + if err := ch.encoder.Flush(); err != nil { + return err + } + return ch.process() +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_profile_info.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_profile_info.go new file mode 100644 index 0000000000..97bc9c791c --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_profile_info.go @@ -0,0 +1,37 @@ +package clickhouse + +type profileInfo struct { + rows uint64 + bytes uint64 + blocks uint64 + appliedLimit bool + rowsBeforeLimit uint64 + calculatedRowsBeforeLimit bool +} + +func (ch *clickhouse) profileInfo() (*profileInfo, error) { + var ( + p profileInfo + err error + ) + if p.rows, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + if p.blocks, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + if p.bytes, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + + if p.appliedLimit, err = ch.decoder.Bool(); err != nil { + return nil, err + } + if p.rowsBeforeLimit, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + if p.calculatedRowsBeforeLimit, err = ch.decoder.Bool(); err != nil { + return nil, err + } + return &p, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_progress.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_progress.go new file mode 100644 index 0000000000..2ccc5fd942 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_progress.go @@ -0,0 +1,26 @@ +package clickhouse + +type progress struct { + rows uint64 + bytes uint64 + totalRows uint64 +} + +func (ch *clickhouse) progress() (*progress, error) { + var ( + p progress + err error + ) + if p.rows, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + if p.bytes, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + + if p.totalRows, err = ch.decoder.Uvarint(); err != nil { + return nil, err + } + + return &p, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_read_block.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_read_block.go new file mode 100644 index 0000000000..e9a3384dce --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_read_block.go @@ -0,0 +1,19 @@ +package clickhouse + +import ( + "github.com/ClickHouse/clickhouse-go/lib/data" +) + +func (ch *clickhouse) readBlock() (*data.Block, error) { + if _, err := ch.decoder.String(); err != nil { // temporary table + return nil, err + } + + ch.decoder.SelectCompress(ch.compress) + var block data.Block + if err := block.Read(&ch.ServerInfo, ch.decoder); err != nil { + return nil, err + } + ch.decoder.SelectCompress(false) + return &block, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_read_meta.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_read_meta.go new file mode 100644 index 0000000000..83e18dc146 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_read_meta.go @@ -0,0 +1,53 @@ +package clickhouse + +import ( + "fmt" + + "github.com/ClickHouse/clickhouse-go/lib/data" + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +func (ch *clickhouse) readMeta() (*data.Block, error) { + for { + packet, err := ch.decoder.Uvarint() + if err != nil { + return nil, err + } + + switch packet { + case protocol.ServerException: + ch.logf("[read meta] <- exception") + return nil, ch.exception() + case protocol.ServerProgress: + progress, err := ch.progress() + if err != nil { + return nil, err + } + ch.logf("[read meta] <- progress: rows=%d, bytes=%d, total rows=%d", + progress.rows, + progress.bytes, + progress.totalRows, + ) + case protocol.ServerProfileInfo: + profileInfo, err := ch.profileInfo() + if err != nil { + return nil, err + } + ch.logf("[read meta] <- profiling: rows=%d, bytes=%d, blocks=%d", profileInfo.rows, profileInfo.bytes, profileInfo.blocks) + case protocol.ServerData: + block, err := ch.readBlock() + if err != nil { + return nil, err + } + ch.logf("[read meta] <- data: packet=%d, columns=%d, rows=%d", packet, block.NumColumns, block.NumRows) + return block, nil + case protocol.ServerEndOfStream: + _, err := ch.readBlock() + ch.logf("[process] <- end of stream") + return nil, err + default: + ch.conn.Close() + return nil, fmt.Errorf("[read meta] unexpected packet [%d] from server", packet) + } + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_external_data.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_external_data.go new file mode 100644 index 0000000000..706a6c5856 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_external_data.go @@ -0,0 +1,35 @@ +package clickhouse + +import "github.com/ClickHouse/clickhouse-go/lib/data" + +func (ch *clickhouse) sendExternalTables(externalTables []ExternalTable) error { + ch.logf("[send external tables] count %d", len(externalTables)) + if externalTables == nil || len(externalTables) == 0 { + return nil + } + block := &data.Block{} + sentTables := make(map[string]bool, 0) + for _, externalTable := range externalTables { + if _, ok := sentTables[externalTable.Name]; ok { + continue + } + ch.logf("[send external table] name %s", externalTable.Name) + sentTables[externalTable.Name] = true + block.Columns = externalTable.Columns + block.NumColumns = uint64(len(externalTable.Columns)) + for _, row := range externalTable.Values { + err := block.AppendRow(row) + if err != nil { + return err + } + } + if err := ch.writeBlock(block, externalTable.Name); err != nil { + return err + } + if err := ch.encoder.Flush(); err != nil { + return err + } + block.Reset() + } + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_query.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_query.go new file mode 100644 index 0000000000..0717ed7797 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_send_query.go @@ -0,0 +1,71 @@ +package clickhouse + +import ( + "context" + "github.com/ClickHouse/clickhouse-go/lib/data" + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +func (ch *clickhouse) sendQuery(ctx context.Context, query string, externalTables []ExternalTable) error { + ch.logf("[send query] %s", query) + if err := ch.encoder.Uvarint(protocol.ClientQuery); err != nil { + return err + } + var queryID string + queryIDValue := ctx.Value(queryIDKey) + if queryIDValue != nil { + if queryIdStr, ok := queryIDValue.(string); ok { + queryID = queryIdStr + } + } + if err := ch.encoder.String(queryID); err != nil { + return err + } + { // client info + ch.encoder.Uvarint(1) + ch.encoder.String("") + ch.encoder.String("") + ch.encoder.String("[::ffff:127.0.0.1]:0") + ch.encoder.Uvarint(1) // iface type TCP + ch.encoder.String(hostname) + ch.encoder.String(hostname) + } + if err := ch.ClientInfo.Write(ch.encoder); err != nil { + return err + } + if ch.ServerInfo.Revision >= protocol.DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO { + ch.encoder.String("") + } + + // the settings are written as list of contiguous name-value pairs, finished with empty name + if !ch.settings.IsEmpty() { + ch.logf("[query settings] %s", ch.settings.settingsStr) + if err := ch.settings.Serialize(ch.encoder); err != nil { + return err + } + } + // empty string is a marker of the end of the settings + if err := ch.encoder.String(""); err != nil { + return err + } + if err := ch.encoder.Uvarint(protocol.StateComplete); err != nil { + return err + } + compress := protocol.CompressDisable + if ch.compress { + compress = protocol.CompressEnable + } + if err := ch.encoder.Uvarint(compress); err != nil { + return err + } + if err := ch.encoder.String(query); err != nil { + return err + } + if err := ch.sendExternalTables(externalTables); err != nil { + return err + } + if err := ch.writeBlock(&data.Block{}, ""); err != nil { + return err + } + return ch.encoder.Flush() +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_write_block.go b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_write_block.go new file mode 100644 index 0000000000..5a76f49799 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/clickhouse_write_block.go @@ -0,0 +1,40 @@ +package clickhouse + +import ( + "github.com/ClickHouse/clickhouse-go/lib/data" + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +func (ch *clickhouse) writeBlock(block *data.Block, tableName string) error { + ch.Lock() + defer ch.Unlock() + if err := ch.encoder.Uvarint(protocol.ClientData); err != nil { + return err + } + + if err := ch.encoder.String(tableName); err != nil { // temporary table + return err + } + + // implement CityHash v 1.0.2 and add LZ4 compression + /* + From Alexey Milovidov + Насколько я помню, сжимаются блоки с данными Native формата, а всё остальное (всякие номера пакетов и т. п.) передаётся без сжатия. + + Сжатые данные устроены так. Они представляют собой набор сжатых фреймов. + Каждый фрейм имеет следующий вид: + чексумма (16 байт), + идентификатор алгоритма сжатия (1 байт), + размер сжатых данных (4 байта, little endian, размер не включает в себя чексумму, но включает в себя остальные 9 байт заголовка), + размер несжатых данных (4 байта, little endian), затем сжатые данные. + Идентификатор алгоритма: 0x82 - lz4, 0x90 - zstd. + Чексумма - CityHash128 из CityHash версии 1.0.2, вычисленный от сжатых данных с учётом 9 байт заголовка. + + См. CompressedReadBufferBase, CompressedWriteBuffer, + utils/compressor, TCPHandler. + */ + ch.encoder.SelectCompress(ch.compress) + err := block.Write(&ch.ServerInfo, ch.encoder) + ch.encoder.SelectCompress(false) + return err +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/connect.go b/vendor/github.com/ClickHouse/clickhouse-go/connect.go new file mode 100644 index 0000000000..14cb1c81ce --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/connect.go @@ -0,0 +1,225 @@ +package clickhouse + +import ( + "bufio" + "crypto/tls" + "database/sql/driver" + "net" + "sync" + "sync/atomic" + "time" +) + +var tick int32 + +type openStrategy int8 + +func (s openStrategy) String() string { + switch s { + case connOpenInOrder: + return "in_order" + case connOpenTimeRandom: + return "time_random" + } + return "random" +} + +const ( + connOpenRandom openStrategy = iota + 1 + connOpenInOrder + connOpenTimeRandom +) + +type connOptions struct { + secure, skipVerify bool + tlsConfig *tls.Config + hosts []string + connTimeout, readTimeout, writeTimeout time.Duration + noDelay bool + openStrategy openStrategy + logf func(string, ...interface{}) +} + +// DialFunc is a function which can be used to establish the network connection. +// Custom dial functions must be registered with RegisterDial +type DialFunc func(network, address string, timeout time.Duration, config *tls.Config) (net.Conn, error) + +var ( + customDialLock sync.RWMutex + customDial DialFunc +) + +// RegisterDial registers a custom dial function. +func RegisterDial(dial DialFunc) { + customDialLock.Lock() + customDial = dial + customDialLock.Unlock() +} + +// DeregisterDial deregisters the custom dial function. +func DeregisterDial() { + customDialLock.Lock() + customDial = nil + customDialLock.Unlock() +} +func dial(options connOptions) (*connect, error) { + var ( + err error + abs = func(v int) int { + if v < 0 { + return -1 * v + } + return v + } + conn net.Conn + ident = abs(int(atomic.AddInt32(&tick, 1))) + ) + tlsConfig := options.tlsConfig + if options.secure { + if tlsConfig == nil { + tlsConfig = &tls.Config{} + } + tlsConfig.InsecureSkipVerify = options.skipVerify + } + checkedHosts := make(map[int]struct{}, len(options.hosts)) + for i := range options.hosts { + var num int + switch options.openStrategy { + case connOpenInOrder: + num = i + case connOpenRandom: + num = (ident + i) % len(options.hosts) + case connOpenTimeRandom: + // select host based on milliseconds + num = int((time.Now().UnixNano()/1000)%1000) % len(options.hosts) + for _, ok := checkedHosts[num]; ok; _, ok = checkedHosts[num] { + num = int(time.Now().UnixNano()) % len(options.hosts) + } + checkedHosts[num] = struct{}{} + } + customDialLock.RLock() + cd := customDial + customDialLock.RUnlock() + switch { + case options.secure: + if cd != nil { + conn, err = cd("tcp", options.hosts[num], options.connTimeout, tlsConfig) + } else { + conn, err = tls.DialWithDialer( + &net.Dialer{ + Timeout: options.connTimeout, + }, + "tcp", + options.hosts[num], + tlsConfig, + ) + } + default: + if cd != nil { + conn, err = cd("tcp", options.hosts[num], options.connTimeout, nil) + } else { + conn, err = net.DialTimeout("tcp", options.hosts[num], options.connTimeout) + } + } + if err == nil { + options.logf( + "[dial] secure=%t, skip_verify=%t, strategy=%s, ident=%d, server=%d -> %s", + options.secure, + options.skipVerify, + options.openStrategy, + ident, + num, + conn.RemoteAddr(), + ) + if tcp, ok := conn.(*net.TCPConn); ok { + err = tcp.SetNoDelay(options.noDelay) // Disable or enable the Nagle Algorithm for this tcp socket + if err != nil { + return nil, err + } + } + return &connect{ + Conn: conn, + logf: options.logf, + ident: ident, + buffer: bufio.NewReader(conn), + readTimeout: options.readTimeout, + writeTimeout: options.writeTimeout, + }, nil + } else { + options.logf( + "[dial err] secure=%t, skip_verify=%t, strategy=%s, ident=%d, addr=%s\n%#v", + options.secure, + options.skipVerify, + options.openStrategy, + ident, + options.hosts[num], + err, + ) + } + } + return nil, err +} + +type connect struct { + net.Conn + logf func(string, ...interface{}) + ident int + buffer *bufio.Reader + closed bool + readTimeout time.Duration + writeTimeout time.Duration + lastReadDeadlineTime time.Time + lastWriteDeadlineTime time.Time +} + +func (conn *connect) Read(b []byte) (int, error) { + var ( + n int + err error + total int + dstLen = len(b) + ) + if currentTime := now(); conn.readTimeout != 0 && currentTime.Sub(conn.lastReadDeadlineTime) > (conn.readTimeout>>2) { + conn.SetReadDeadline(time.Now().Add(conn.readTimeout)) + conn.lastReadDeadlineTime = currentTime + } + for total < dstLen { + if n, err = conn.buffer.Read(b[total:]); err != nil { + conn.logf("[connect] read error: %v", err) + conn.Close() + return n, driver.ErrBadConn + } + total += n + } + return total, nil +} + +func (conn *connect) Write(b []byte) (int, error) { + var ( + n int + err error + total int + srcLen = len(b) + ) + if currentTime := now(); conn.writeTimeout != 0 && currentTime.Sub(conn.lastWriteDeadlineTime) > (conn.writeTimeout>>2) { + conn.SetWriteDeadline(time.Now().Add(conn.writeTimeout)) + conn.lastWriteDeadlineTime = currentTime + } + for total < srcLen { + if n, err = conn.Conn.Write(b[total:]); err != nil { + conn.logf("[connect] write error: %v", err) + conn.Close() + return n, driver.ErrBadConn + } + total += n + } + return n, nil +} + +func (conn *connect) Close() error { + if !conn.closed { + conn.closed = true + return conn.Conn.Close() + } + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/connect_check.go b/vendor/github.com/ClickHouse/clickhouse-go/connect_check.go new file mode 100644 index 0000000000..4b01a13e9f --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/connect_check.go @@ -0,0 +1,57 @@ +// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos + +package clickhouse + +import ( + "errors" + "fmt" + "io" + "syscall" + "time" +) + +var errUnexpectedRead = errors.New("unexpected read from socket") + +func (conn *connect) connCheck() error { + var sysErr error + + sysConn, ok := conn.Conn.(syscall.Conn) + if !ok { + return nil + } + rawConn, err := sysConn.SyscallConn() + if err != nil { + return err + } + // If this connection has a ReadTimeout which we've been setting on + // reads, reset it to zero value before we attempt a non-blocking + // read, otherwise we may get os.ErrDeadlineExceeded for the cached + // connection from the pool with an expired timeout. + if conn.readTimeout != 0 { + err = conn.SetReadDeadline(time.Time{}) + if err != nil { + return fmt.Errorf("set read deadline: %w", err) + } + conn.lastReadDeadlineTime = time.Time{} + } + err = rawConn.Read(func(fd uintptr) bool { + var buf [1]byte + n, err := syscall.Read(int(fd), buf[:]) + switch { + case n == 0 && err == nil: + sysErr = io.EOF + case n > 0: + sysErr = errUnexpectedRead + case err == syscall.EAGAIN || err == syscall.EWOULDBLOCK: + sysErr = nil + default: + sysErr = err + } + return true + }) + if err != nil { + return err + } + + return sysErr +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/connect_check_dummy.go b/vendor/github.com/ClickHouse/clickhouse-go/connect_check_dummy.go new file mode 100644 index 0000000000..c8cc74e418 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/connect_check_dummy.go @@ -0,0 +1,7 @@ +// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos + +package clickhouse + +func (conn *connect) connCheck() error { + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/docker-compose.yml b/vendor/github.com/ClickHouse/clickhouse-go/docker-compose.yml new file mode 100644 index 0000000000..2d03214ba1 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/docker-compose.yml @@ -0,0 +1,9 @@ +--- +version: '3' +services: + clickhouse: + image: yandex/clickhouse-server + ports: + - 127.0.0.1:8123:8123 + - 127.0.0.1:9000:9000 + - 127.0.0.1:9009:9009 diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/go.test.sh b/vendor/github.com/ClickHouse/clickhouse-go/go.test.sh similarity index 100% rename from vendor/github.com/ClickHouse/clickhouse-go/v2/go.test.sh rename to vendor/github.com/ClickHouse/clickhouse-go/go.test.sh diff --git a/vendor/github.com/ClickHouse/clickhouse-go/helpers.go b/vendor/github.com/ClickHouse/clickhouse-go/helpers.go new file mode 100644 index 0000000000..7e10d06204 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/helpers.go @@ -0,0 +1,144 @@ +package clickhouse + +import ( + "bytes" + "database/sql/driver" + "fmt" + "reflect" + "regexp" + "strings" + "time" +) + +func numInput(query string) int { + + var ( + count int + args = make(map[string]struct{}) + reader = bytes.NewReader([]byte(query)) + quote, gravis bool + escape bool + keyword bool + inBetween bool + like = newMatcher("like") + limit = newMatcher("limit") + offset = newMatcher("offset") + between = newMatcher("between") + in = newMatcher("in") + and = newMatcher("and") + from = newMatcher("from") + join = newMatcher("join") + subSelect = newMatcher("select") + ) + for { + if char, _, err := reader.ReadRune(); err == nil { + if escape { + escape = false + continue + } + switch char { + case '\\': + if gravis || quote { + escape = true + } + case '\'': + if !gravis { + quote = !quote + } + case '`': + if !quote { + gravis = !gravis + } + } + if quote || gravis { + continue + } + switch { + case char == '?' && keyword: + count++ + case char == '@': + if param := paramParser(reader); len(param) != 0 { + if _, found := args[param]; !found { + args[param] = struct{}{} + count++ + } + } + case + char == '=', + char == '<', + char == '>', + char == '(', + char == ',', + char == '[', + char == '%': + keyword = true + default: + if limit.matchRune(char) || offset.matchRune(char) || like.matchRune(char) || + in.matchRune(char) || from.matchRune(char) || join.matchRune(char) || subSelect.matchRune(char) { + keyword = true + } else if between.matchRune(char) { + keyword = true + inBetween = true + } else if inBetween && and.matchRune(char) { + keyword = true + inBetween = false + } else { + keyword = keyword && (char == ' ' || char == '\t' || char == '\n') + } + } + } else { + break + } + } + return count +} + +func paramParser(reader *bytes.Reader) string { + var name bytes.Buffer + for { + if char, _, err := reader.ReadRune(); err == nil { + if char == '_' || char >= '0' && char <= '9' || 'a' <= char && char <= 'z' || 'A' <= char && char <= 'Z' { + name.WriteRune(char) + } else { + reader.UnreadRune() + break + } + } else { + break + } + } + return name.String() +} + +var selectRe = regexp.MustCompile(`\s+SELECT\s+`) + +func isInsert(query string) bool { + if f := strings.Fields(query); len(f) > 2 { + return strings.EqualFold("INSERT", f[0]) && strings.EqualFold("INTO", f[1]) && !selectRe.MatchString(strings.ToUpper(query)) + } + return false +} + +func quote(v driver.Value) string { + switch v := reflect.ValueOf(v); v.Kind() { + case reflect.Slice: + values := make([]string, 0, v.Len()) + for i := 0; i < v.Len(); i++ { + values = append(values, quote(v.Index(i).Interface())) + } + return strings.Join(values, ", ") + } + switch v := v.(type) { + case string: + return "'" + strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(v) + "'" + case time.Time: + return formatTime(v) + case nil: + return "null" + } + return fmt.Sprint(v) +} + +func formatTime(v time.Time) string { + return v.Format("toDateTime('2006-01-02 15:04:05', '" + v.Location().String() + "')") +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_reader.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_reader.go new file mode 100644 index 0000000000..be428b3648 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_reader.go @@ -0,0 +1,107 @@ +// +build !clz4 + +package binary + +import ( + "encoding/binary" + "fmt" + "io" + + "github.com/ClickHouse/clickhouse-go/lib/lz4" +) + +type compressReader struct { + reader io.Reader + // data uncompressed + data []byte + // data position + pos int + // data compressed + zdata []byte + // lz4 headers + header []byte +} + +// NewCompressReader wrap the io.Reader +func NewCompressReader(r io.Reader) *compressReader { + p := &compressReader{ + reader: r, + header: make([]byte, HeaderSize), + } + p.data = make([]byte, BlockMaxSize, BlockMaxSize) + + zlen := lz4.CompressBound(BlockMaxSize) + HeaderSize + p.zdata = make([]byte, zlen, zlen) + + p.pos = len(p.data) + return p +} + +func (cr *compressReader) Read(buf []byte) (n int, err error) { + var bytesRead = 0 + n = len(buf) + + if cr.pos < len(cr.data) { + copyedSize := copy(buf, cr.data[cr.pos:]) + + bytesRead += copyedSize + cr.pos += copyedSize + } + + for bytesRead < n { + if err = cr.readCompressedData(); err != nil { + return bytesRead, err + } + copyedSize := copy(buf[bytesRead:], cr.data) + + bytesRead += copyedSize + cr.pos = copyedSize + } + return n, nil +} + +func (cr *compressReader) readCompressedData() (err error) { + cr.pos = 0 + var n int + n, err = cr.reader.Read(cr.header) + if err != nil { + return + } + if n != len(cr.header) { + return fmt.Errorf("Lz4 decompression header EOF") + } + + compressedSize := int(binary.LittleEndian.Uint32(cr.header[17:])) - 9 + decompressedSize := int(binary.LittleEndian.Uint32(cr.header[21:])) + + if compressedSize > cap(cr.zdata) { + cr.zdata = make([]byte, compressedSize) + } + if decompressedSize > cap(cr.data) { + cr.data = make([]byte, decompressedSize) + } + + cr.zdata = cr.zdata[:compressedSize] + cr.data = cr.data[:decompressedSize] + + // @TODO checksum + if cr.header[16] == LZ4 { + n, err = cr.reader.Read(cr.zdata) + if err != nil { + return + } + + if n != len(cr.zdata) { + return fmt.Errorf("Decompress read size not match") + } + + _, err = lz4.Decode(cr.data, cr.zdata) + if err != nil { + return + } + } else { + return fmt.Errorf("Unknown compression method: 0x%02x ", cr.header[16]) + } + + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_reader_clz4.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_reader_clz4.go new file mode 100644 index 0000000000..2845b3b8be --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_reader_clz4.go @@ -0,0 +1,107 @@ +// +build clz4 + +package binary + +import ( + "encoding/binary" + "fmt" + "io" + + lz4 "github.com/cloudflare/golz4" +) + +type compressReader struct { + reader io.Reader + // data uncompressed + data []byte + // data position + pos int + // data compressed + zdata []byte + // lz4 headers + header []byte +} + +// NewCompressReader wrap the io.Reader +func NewCompressReader(r io.Reader) *compressReader { + p := &compressReader{ + reader: r, + header: make([]byte, HeaderSize), + } + p.data = make([]byte, BlockMaxSize, BlockMaxSize) + + zlen := lz4.CompressBound(p.data) + HeaderSize + p.zdata = make([]byte, zlen, zlen) + + p.pos = len(p.data) + return p +} + +func (cr *compressReader) Read(buf []byte) (n int, err error) { + var bytesRead = 0 + n = len(buf) + + if cr.pos < len(cr.data) { + copyedSize := copy(buf, cr.data[cr.pos:]) + + bytesRead += copyedSize + cr.pos += copyedSize + } + + for bytesRead < n { + if err = cr.readCompressedData(); err != nil { + return bytesRead, err + } + copyedSize := copy(buf[bytesRead:], cr.data) + + bytesRead += copyedSize + cr.pos = copyedSize + } + return n, nil +} + +func (cr *compressReader) readCompressedData() (err error) { + cr.pos = 0 + var n int + n, err = cr.reader.Read(cr.header) + if err != nil { + return + } + if n != len(cr.header) { + return fmt.Errorf("Lz4 decompression header EOF") + } + + compressedSize := int(binary.LittleEndian.Uint32(cr.header[17:])) - 9 + decompressedSize := int(binary.LittleEndian.Uint32(cr.header[21:])) + + if compressedSize > cap(cr.zdata) { + cr.zdata = make([]byte, compressedSize) + } + if decompressedSize > cap(cr.data) { + cr.data = make([]byte, decompressedSize) + } + + cr.zdata = cr.zdata[:compressedSize] + cr.data = cr.data[:decompressedSize] + + // @TODO checksum + if cr.header[16] == LZ4 { + n, err = cr.reader.Read(cr.zdata) + if err != nil { + return + } + + if n != len(cr.zdata) { + return fmt.Errorf("Decompress read size not match") + } + + err = lz4.Uncompress(cr.zdata, cr.data) + if err != nil { + return + } + } else { + return fmt.Errorf("Unknown compression method: 0x%02x ", cr.header[16]) + } + + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_settings.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_settings.go new file mode 100644 index 0000000000..ca4559976a --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_settings.go @@ -0,0 +1,21 @@ +package binary + +type CompressionMethodByte byte + +const ( + NONE CompressionMethodByte = 0x02 + LZ4 = 0x82 + ZSTD = 0x90 +) + +const ( + // ChecksumSize is 128bits for cityhash102 checksum + ChecksumSize = 16 + // CompressHeader magic + compressed_size + uncompressed_size + CompressHeaderSize = 1 + 4 + 4 + + // HeaderSize + HeaderSize = ChecksumSize + CompressHeaderSize + // BlockMaxSize 1MB + BlockMaxSize = 1 << 20 +) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_writer.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_writer.go new file mode 100644 index 0000000000..e4a73cf018 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_writer.go @@ -0,0 +1,79 @@ +// +build !clz4 + +package binary + +import ( + "encoding/binary" + "io" + + "github.com/ClickHouse/clickhouse-go/lib/cityhash102" + "github.com/ClickHouse/clickhouse-go/lib/lz4" +) + +type compressWriter struct { + writer io.Writer + // data uncompressed + data []byte + // data position + pos int + // data compressed + zdata []byte +} + +// NewCompressWriter wrap the io.Writer +func NewCompressWriter(w io.Writer) *compressWriter { + p := &compressWriter{writer: w} + p.data = make([]byte, BlockMaxSize, BlockMaxSize) + + zlen := lz4.CompressBound(BlockMaxSize) + HeaderSize + p.zdata = make([]byte, zlen, zlen) + return p +} + +func (cw *compressWriter) Write(buf []byte) (int, error) { + var n int + for len(buf) > 0 { + // Accumulate the data to be compressed. + m := copy(cw.data[cw.pos:], buf) + cw.pos += m + buf = buf[m:] + + if cw.pos == len(cw.data) { + err := cw.Flush() + if err != nil { + return n, err + } + } + n += m + } + return n, nil +} + +func (cw *compressWriter) Flush() (err error) { + if cw.pos == 0 { + return + } + + // write the headers + compressedSize, err := lz4.Encode(cw.zdata[HeaderSize:], cw.data[:cw.pos]) + if err != nil { + return err + } + compressedSize += CompressHeaderSize + // fill the header, compressed_size_32 + uncompressed_size_32 + cw.zdata[16] = LZ4 + binary.LittleEndian.PutUint32(cw.zdata[17:], uint32(compressedSize)) + binary.LittleEndian.PutUint32(cw.zdata[21:], uint32(cw.pos)) + + // fill the checksum + checkSum := cityhash102.CityHash128(cw.zdata[16:], uint32(compressedSize)) + binary.LittleEndian.PutUint64(cw.zdata[0:], checkSum.Lower64()) + binary.LittleEndian.PutUint64(cw.zdata[8:], checkSum.Higher64()) + + cw.writer.Write(cw.zdata[:compressedSize+ChecksumSize]) + if w, ok := cw.writer.(WriteFlusher); ok { + err = w.Flush() + } + cw.pos = 0 + return +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_writer_clz4.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_writer_clz4.go new file mode 100644 index 0000000000..1302e16113 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/compress_writer_clz4.go @@ -0,0 +1,78 @@ +// +build clz4 + +package binary + +import ( + "encoding/binary" + "io" + + lz4 "github.com/cloudflare/golz4" + "github.com/ClickHouse/clickhouse-go/lib/cityhash102" +) + +type compressWriter struct { + writer io.Writer + // data uncompressed + data []byte + // data position + pos int + // data compressed + zdata []byte +} + +// NewCompressWriter wrap the io.Writer +func NewCompressWriter(w io.Writer) *compressWriter { + p := &compressWriter{writer: w} + p.data = make([]byte, BlockMaxSize, BlockMaxSize) + + zlen := lz4.CompressBound(p.data) + HeaderSize + p.zdata = make([]byte, zlen, zlen) + return p +} + +func (cw *compressWriter) Write(buf []byte) (int, error) { + var n int + for len(buf) > 0 { + // Accumulate the data to be compressed. + m := copy(cw.data[cw.pos:], buf) + cw.pos += m + buf = buf[m:] + + if cw.pos == len(cw.data) { + err := cw.Flush() + if err != nil { + return n, err + } + } + n += m + } + return n, nil +} + +func (cw *compressWriter) Flush() (err error) { + if cw.pos == 0 { + return + } + // write the headers + compressedSize, err := lz4.Compress(cw.data[:cw.pos], cw.zdata[HeaderSize:]) + if err != nil { + return err + } + compressedSize += CompressHeaderSize + // fill the header, compressed_size_32 + uncompressed_size_32 + cw.zdata[16] = LZ4 + binary.LittleEndian.PutUint32(cw.zdata[17:], uint32(compressedSize)) + binary.LittleEndian.PutUint32(cw.zdata[21:], uint32(cw.pos)) + + // fill the checksum + checkSum := cityhash102.CityHash128(cw.zdata[16:], uint32(compressedSize)) + binary.LittleEndian.PutUint64(cw.zdata[0:], checkSum.Lower64()) + binary.LittleEndian.PutUint64(cw.zdata[8:], checkSum.Higher64()) + + cw.writer.Write(cw.zdata[:compressedSize+ChecksumSize]) + if w, ok := cw.writer.(WriteFlusher); ok { + err = w.Flush() + } + cw.pos = 0 + return +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/decoder.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/decoder.go similarity index 64% rename from vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/decoder.go rename to vendor/github.com/ClickHouse/clickhouse-go/lib/binary/decoder.go index 6f34f2e882..1bf213be74 100644 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/decoder.go +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/decoder.go @@ -1,20 +1,3 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - package binary import ( @@ -23,26 +6,35 @@ import ( "math" ) -func NewDecoder(r io.Reader) *Decoder { +func NewDecoder(input io.Reader) *Decoder { return &Decoder{ - input: r, + input: input, + } +} + +func NewDecoderWithCompress(input io.Reader) *Decoder { + return &Decoder{ + input: input, + compressInput: NewCompressReader(input), } } type Decoder struct { - input io.Reader - scratch [binary.MaxVarintLen64]byte + compress bool + input io.Reader + compressInput io.Reader + scratch [binary.MaxVarintLen64]byte } -func (decoder *Decoder) Raw(b []byte) error { - n, err := decoder.input.Read(b) - if err != nil { - return nil +func (decoder *Decoder) SelectCompress(compress bool) { + decoder.compress = compress +} + +func (decoder *Decoder) Get() io.Reader { + if decoder.compress && decoder.compressInput != nil { + return decoder.compressInput } - if n != len(b) { - return io.EOF - } - return nil + return decoder.input } func (decoder *Decoder) Bool() (bool, error) { @@ -98,14 +90,14 @@ func (decoder *Decoder) UInt8() (uint8, error) { } func (decoder *Decoder) UInt16() (uint16, error) { - if _, err := decoder.input.Read(decoder.scratch[:2]); err != nil { + if _, err := decoder.Get().Read(decoder.scratch[:2]); err != nil { return 0, err } return uint16(decoder.scratch[0]) | uint16(decoder.scratch[1])<<8, nil } func (decoder *Decoder) UInt32() (uint32, error) { - if _, err := decoder.input.Read(decoder.scratch[:4]); err != nil { + if _, err := decoder.Get().Read(decoder.scratch[:4]); err != nil { return 0, err } return uint32(decoder.scratch[0]) | @@ -115,7 +107,7 @@ func (decoder *Decoder) UInt32() (uint32, error) { } func (decoder *Decoder) UInt64() (uint64, error) { - if _, err := decoder.input.Read(decoder.scratch[:8]); err != nil { + if _, err := decoder.Get().Read(decoder.scratch[:8]); err != nil { return 0, err } return uint64(decoder.scratch[0]) | @@ -145,11 +137,11 @@ func (decoder *Decoder) Float64() (float64, error) { } func (decoder *Decoder) Fixed(ln int) ([]byte, error) { - if reader, ok := decoder.input.(interface{ Fixed(ln int) ([]byte, error) }); ok { + if reader, ok := decoder.Get().(FixedReader); ok { return reader.Fixed(ln) } buf := make([]byte, ln) - if _, err := decoder.input.Read(buf); err != nil { + if _, err := decoder.Get().Read(buf); err != nil { return nil, err } return buf, nil @@ -167,9 +159,19 @@ func (decoder *Decoder) String() (string, error) { return string(str), nil } +func (decoder *Decoder) Decimal128() ([]byte, error) { + bytes := make([]byte, 16) + _, err := decoder.Get().Read(bytes) + return bytes, err +} + func (decoder *Decoder) ReadByte() (byte, error) { - if _, err := decoder.input.Read(decoder.scratch[:1]); err != nil { + if _, err := decoder.Get().Read(decoder.scratch[:1]); err != nil { return 0x0, err } return decoder.scratch[0], nil } + +type FixedReader interface { + Fixed(ln int) ([]byte, error) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/encoder.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/encoder.go new file mode 100644 index 0000000000..b4571b7e52 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/binary/encoder.go @@ -0,0 +1,199 @@ +package binary + +import ( + "encoding/binary" + "io" + "math" + "reflect" + "unsafe" +) + +func NewEncoder(w io.Writer) *Encoder { + return &Encoder{ + output: w, + } +} + +func NewEncoderWithCompress(w io.Writer) *Encoder { + return &Encoder{ + output: w, + compressOutput: NewCompressWriter(w), + } +} + +type Encoder struct { + compress bool + output io.Writer + compressOutput io.Writer + scratch [binary.MaxVarintLen64]byte +} + +func (enc *Encoder) SelectCompress(compress bool) { + if enc.compressOutput == nil { + return + } + if enc.compress && !compress { + enc.Flush() + } + enc.compress = compress +} + +func (enc *Encoder) Get() io.Writer { + if enc.compress && enc.compressOutput != nil { + return enc.compressOutput + } + return enc.output +} + +func (enc *Encoder) Uvarint(v uint64) error { + ln := binary.PutUvarint(enc.scratch[:binary.MaxVarintLen64], v) + if _, err := enc.Get().Write(enc.scratch[0:ln]); err != nil { + return err + } + return nil +} + +func (enc *Encoder) Bool(v bool) error { + if v { + return enc.UInt8(1) + } + return enc.UInt8(0) +} + +func (enc *Encoder) Int8(v int8) error { + return enc.UInt8(uint8(v)) +} + +func (enc *Encoder) Int16(v int16) error { + return enc.UInt16(uint16(v)) +} + +func (enc *Encoder) Int32(v int32) error { + return enc.UInt32(uint32(v)) +} + +func (enc *Encoder) Int64(v int64) error { + return enc.UInt64(uint64(v)) +} + +func (enc *Encoder) UInt8(v uint8) error { + enc.scratch[0] = v + if _, err := enc.Get().Write(enc.scratch[:1]); err != nil { + return err + } + return nil +} + +func (enc *Encoder) UInt16(v uint16) error { + enc.scratch[0] = byte(v) + enc.scratch[1] = byte(v >> 8) + if _, err := enc.Get().Write(enc.scratch[:2]); err != nil { + return err + } + return nil +} + +func (enc *Encoder) UInt32(v uint32) error { + enc.scratch[0] = byte(v) + enc.scratch[1] = byte(v >> 8) + enc.scratch[2] = byte(v >> 16) + enc.scratch[3] = byte(v >> 24) + if _, err := enc.Get().Write(enc.scratch[:4]); err != nil { + return err + } + return nil +} + +func (enc *Encoder) UInt64(v uint64) error { + enc.scratch[0] = byte(v) + enc.scratch[1] = byte(v >> 8) + enc.scratch[2] = byte(v >> 16) + enc.scratch[3] = byte(v >> 24) + enc.scratch[4] = byte(v >> 32) + enc.scratch[5] = byte(v >> 40) + enc.scratch[6] = byte(v >> 48) + enc.scratch[7] = byte(v >> 56) + if _, err := enc.Get().Write(enc.scratch[:8]); err != nil { + return err + } + return nil +} + +func (enc *Encoder) Float32(v float32) error { + return enc.UInt32(math.Float32bits(v)) +} + +func (enc *Encoder) Float64(v float64) error { + return enc.UInt64(math.Float64bits(v)) +} + +func (enc *Encoder) String(v string) error { + str := Str2Bytes(v) + if err := enc.Uvarint(uint64(len(str))); err != nil { + return err + } + if _, err := enc.Get().Write(str); err != nil { + return err + } + return nil +} + +func (enc *Encoder) RawString(str []byte) error { + if err := enc.Uvarint(uint64(len(str))); err != nil { + return err + } + if _, err := enc.Get().Write(str); err != nil { + return err + } + return nil +} + +func (enc *Encoder) Decimal128(bytes []byte) error { + _, err := enc.Get().Write(bytes) + return err +} + +func (enc *Encoder) Write(b []byte) (int, error) { + return enc.Get().Write(b) +} + +func (enc *Encoder) Flush() error { + if w, ok := enc.Get().(WriteFlusher); ok { + return w.Flush() + } + return nil +} + +type WriteFlusher interface { + Flush() error +} + +func Str2Bytes(str string) []byte { + // Copied from https://github.com/m3db/m3/blob/master/src/x/unsafe/string.go#L62 + if len(str) == 0 { + return nil + } + + // We need to declare a real byte slice so internally the compiler + // knows to use an unsafe.Pointer to keep track of the underlying memory so that + // once the slice's array pointer is updated with the pointer to the string's + // underlying bytes, the compiler won't prematurely GC the memory when the string + // goes out of scope. + var b []byte + byteHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b)) + + // This makes sure that even if GC relocates the string's underlying + // memory after this assignment, the corresponding unsafe.Pointer in the internal + // slice struct will be updated accordingly to reflect the memory relocation. + byteHeader.Data = (*reflect.StringHeader)(unsafe.Pointer(&str)).Data + + // It is important that we access str after we assign the Data + // pointer of the string header to the Data pointer of the slice header to + // make sure the string (and the underlying bytes backing the string) don't get + // GC'ed before the assignment happens. + l := len(str) + byteHeader.Len = l + byteHeader.Cap = l + + return b +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/city64.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/city64.go new file mode 100644 index 0000000000..c410c44dca --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/city64.go @@ -0,0 +1,45 @@ +package cityhash102 + +import ( + "encoding/binary" + "hash" +) + +type City64 struct { + s []byte +} + +var _ hash.Hash64 = (*City64)(nil) +var _ hash.Hash = (*City64)(nil) + +func New64() hash.Hash64 { + return &City64{} +} + +func (this *City64) Sum(b []byte) []byte { + b2 := make([]byte, 8) + binary.BigEndian.PutUint64(b2, this.Sum64()) + b = append(b, b2...) + return b +} + +func (this *City64) Sum64() uint64 { + return CityHash64(this.s, uint32(len(this.s))) +} + +func (this *City64) Reset() { + this.s = this.s[0:0] +} + +func (this *City64) BlockSize() int { + return 1 +} + +func (this *City64) Write(s []byte) (n int, err error) { + this.s = append(this.s, s...) + return len(s), nil +} + +func (this *City64) Size() int { + return 8 +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/cityhash.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/cityhash.go similarity index 92% rename from vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/cityhash.go rename to vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/cityhash.go index 410aafda36..dcc666b671 100644 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/cityhash.go +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/cityhash.go @@ -1,20 +1,3 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - /* * Go implementation of Google city hash (MIT license) * https://code.google.com/p/cityhash/ diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/doc.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/doc.go new file mode 100644 index 0000000000..01ee5f8545 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/cityhash102/doc.go @@ -0,0 +1,5 @@ +/** COPY from https://github.com/zentures/cityhash/ + +NOTE: The code is modified to be compatible with CityHash128 used in ClickHouse +*/ +package cityhash102 diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/array.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/array.go new file mode 100644 index 0000000000..a9e052a224 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/array.go @@ -0,0 +1,270 @@ +package column + +import ( + "errors" + "fmt" + "net" + "reflect" + "strings" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type columnDecoder func() (interface{}, error) + +var unsupportedArrayTypeErrTemp = "unsupported Array type '%s'" + +// If you add Nullable type, that can be used in Array(Nullable(T)) add this type to ../codegen/nullable_appender/main.go in structure values.Types. +// Run code generation. +//go:generate go run ../codegen/nullable_appender -package $GOPACKAGE -file nullable_appender.go +type Array struct { + base + depth int + column Column + nullable bool +} + +func (array *Array) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + return nil, fmt.Errorf("do not use Read method for Array(T) column") +} + +func (array *Array) WriteNull(nulls, encoder *binary.Encoder, v interface{}) error { + if array.nullable { + column, ok := array.column.(*Nullable) + if !ok { + return fmt.Errorf("cannot convert to nullable type") + } + return column.WriteNull(nulls, encoder, v) + } + return fmt.Errorf("write null to not nullable array") +} + +func (array *Array) Write(encoder *binary.Encoder, v interface{}) error { + return array.column.Write(encoder, v) +} + +func (array *Array) ReadArray(decoder *binary.Decoder, rows int) (_ []interface{}, err error) { + var ( + offsets = make([][]uint64, array.depth) + values = make([]interface{}, rows) + ) + + // Read offsets + lastOffset := uint64(rows) + for i := 0; i < array.depth; i++ { + offset := make([]uint64, lastOffset) + for j := uint64(0); j < lastOffset; j++ { + if offset[j], err = decoder.UInt64(); err != nil { + return nil, err + } + } + offsets[i] = offset + lastOffset = 0 + if len(offset) > 0 { + lastOffset = offset[len(offset)-1] + } + } + + var cd columnDecoder + + switch column := array.column.(type) { + case *Nullable: + nullRows, err := column.ReadNull(decoder, int(lastOffset)) + if err != nil { + return nil, err + } + cd = func(rows []interface{}) columnDecoder { + i := 0 + return func() (interface{}, error) { + if i > len(rows) { + return nil, errors.New("not enough rows to return while parsing Null column") + } + ret := rows[i] + i++ + return ret, nil + } + }(nullRows) + case *Tuple: + tupleRows, err := column.ReadTuple(decoder, int(lastOffset)) + if err != nil { + return nil, err + } + // closure to return fully assembled tuple values as if they + // were decoded one at a time + cd = func(rows []interface{}) columnDecoder { + i := 0 + return func() (interface{}, error) { + if i > len(rows) { + return nil, errors.New("not enough rows to return while parsing Tuple column") + } + ret := rows[i] + i++ + return ret, nil + } + }(tupleRows) + default: + cd = func(decoder *binary.Decoder) columnDecoder { + return func() (interface{}, error) { return array.column.Read(decoder, array.nullable) } + }(decoder) + } + + // Read values + for i := 0; i < rows; i++ { + if values[i], err = array.read(cd, offsets, uint64(i), 0); err != nil { + return nil, err + } + } + return values, nil +} + +func (array *Array) read(readColumn columnDecoder, offsets [][]uint64, index uint64, level int) (interface{}, error) { + end := offsets[level][index] + start := uint64(0) + if index > 0 { + start = offsets[level][index-1] + } + + scanT := array.column.ScanType() + slice := reflect.MakeSlice(array.arrayType(level), 0, int(end-start)) + for i := start; i < end; i++ { + var ( + value interface{} + err error + ) + if level == array.depth-1 { + value, err = readColumn() + } else { + value, err = array.read(readColumn, offsets, i, level+1) + } + if err != nil { + return nil, err + } + if array.nullable && level == array.depth-1 { + f, ok := nullableAppender[scanT.String()] + if !ok { + return nil, fmt.Errorf(unsupportedArrayTypeErrTemp, scanT.String()) + } + + cSlice, err := f(value, slice) + if err != nil { + return nil, err + } + + slice = cSlice + } else { + slice = reflect.Append(slice, reflect.ValueOf(value)) + } + + } + return slice.Interface(), nil +} + +func (array *Array) arrayType(level int) reflect.Type { + t := array.column.ScanType() + for i := 0; i < array.depth-level; i++ { + t = reflect.SliceOf(t) + } + return t +} + +func (array *Array) Depth() int { + return array.depth +} + +func parseArray(name, chType string, timezone *time.Location) (*Array, error) { + if len(chType) < 11 { + return nil, fmt.Errorf("invalid Array column type: %s", chType) + } + var ( + depth int + columnType = chType + ) + +loop: + for _, str := range strings.Split(chType, "Array(") { + switch { + case len(str) == 0: + depth++ + default: + chType = str[:len(str)-depth] + break loop + } + } + column, err := Factory(name, chType, timezone) + if err != nil { + return nil, fmt.Errorf("Array(T): %v", err) + } + + var scanType interface{} + switch t := column.ScanType(); t { + case arrayBaseTypes[int8(0)]: + scanType = []int8{} + case arrayBaseTypes[int16(0)]: + scanType = []int16{} + case arrayBaseTypes[int32(0)]: + scanType = []int32{} + case arrayBaseTypes[int64(0)]: + scanType = []int64{} + case arrayBaseTypes[uint8(0)]: + scanType = []uint8{} + case arrayBaseTypes[uint16(0)]: + scanType = []uint16{} + case arrayBaseTypes[uint32(0)]: + scanType = []uint32{} + case arrayBaseTypes[uint64(0)]: + scanType = []uint64{} + case arrayBaseTypes[float32(0)]: + scanType = []float32{} + case arrayBaseTypes[float64(0)]: + scanType = []float64{} + case arrayBaseTypes[string("")]: + scanType = []string{} + case arrayBaseTypes[time.Time{}]: + scanType = []time.Time{} + case arrayBaseTypes[IPv4{}], arrayBaseTypes[IPv6{}]: + scanType = []net.IP{} + case reflect.ValueOf([]interface{}{}).Type(): + scanType = [][]interface{}{} + + //nullable + case arrayBaseTypes[ptrInt8T]: + scanType = []*int8{} + case arrayBaseTypes[ptrInt16T]: + scanType = []*int16{} + case arrayBaseTypes[ptrInt32T]: + scanType = []*int32{} + case arrayBaseTypes[ptrInt64T]: + scanType = []*int64{} + case arrayBaseTypes[ptrUInt8T]: + scanType = []*uint8{} + case arrayBaseTypes[ptrUInt16T]: + scanType = []*uint16{} + case arrayBaseTypes[ptrUInt32T]: + scanType = []*uint32{} + case arrayBaseTypes[ptrUInt64T]: + scanType = []*uint64{} + case arrayBaseTypes[ptrFloat32]: + scanType = []*float32{} + case arrayBaseTypes[ptrFloat64]: + scanType = []*float64{} + case arrayBaseTypes[ptrString]: + scanType = []*string{} + case arrayBaseTypes[ptrTime]: + scanType = []*time.Time{} + case arrayBaseTypes[ptrIPv4], arrayBaseTypes[ptrIPv6]: + scanType = []*net.IP{} + default: + return nil, fmt.Errorf(unsupportedArrayTypeErrTemp, column.ScanType().Name()) + } + return &Array{ + base: base{ + name: name, + chType: columnType, + valueOf: reflect.ValueOf(scanType), + }, + depth: depth, + column: column, + nullable: strings.HasPrefix(column.CHType(), "Nullable"), + }, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/column.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/column.go new file mode 100644 index 0000000000..60b1f9692f --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/column.go @@ -0,0 +1,205 @@ +package column + +import ( + "fmt" + "reflect" + "strings" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Column interface { + Name() string + CHType() string + ScanType() reflect.Type + Read(*binary.Decoder, bool) (interface{}, error) + Write(*binary.Encoder, interface{}) error + defaultValue() interface{} + Depth() int +} + +func Factory(name, chType string, timezone *time.Location) (Column, error) { + switch chType { + case "Int8": + return &Int8{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[int8(0)], + }, + }, nil + case "Int16": + return &Int16{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[int16(0)], + }, + }, nil + case "Int32": + return &Int32{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[int32(0)], + }, + }, nil + case "Int64": + return &Int64{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[int64(0)], + }, + }, nil + case "UInt8": + return &UInt8{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[uint8(0)], + }, + }, nil + case "UInt16": + return &UInt16{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[uint16(0)], + }, + }, nil + case "UInt32": + return &UInt32{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[uint32(0)], + }, + }, nil + case "UInt64": + return &UInt64{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[uint64(0)], + }, + }, nil + case "Float32": + return &Float32{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[float32(0)], + }, + }, nil + case "Float64": + return &Float64{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[float64(0)], + }, + }, nil + case "String": + return &String{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[string("")], + }, + }, nil + case "UUID": + return &UUID{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[string("")], + }, + }, nil + case "Date": + _, offset := time.Unix(0, 0).In(timezone).Zone() + return &Date{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[time.Time{}], + }, + Timezone: timezone, + offset: int64(offset), + }, nil + case "IPv4": + return &IPv4{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[IPv4{}], + }, + }, nil + case "IPv6": + return &IPv6{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[IPv6{}], + }, + }, nil + } + switch { + case strings.HasPrefix(chType, "DateTime") && !strings.HasPrefix(chType, "DateTime64"): + return &DateTime{ + base: base{ + name: name, + chType: "DateTime", + valueOf: columnBaseTypes[time.Time{}], + }, + Timezone: timezone, + }, nil + case strings.HasPrefix(chType, "DateTime64"): + return &DateTime64{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[time.Time{}], + }, + Timezone: timezone, + }, nil + case strings.HasPrefix(chType, "Array"): + return parseArray(name, chType, timezone) + case strings.HasPrefix(chType, "Nullable"): + return parseNullable(name, chType, timezone) + case strings.HasPrefix(chType, "FixedString"): + return parseFixedString(name, chType) + case strings.HasPrefix(chType, "Enum8"), strings.HasPrefix(chType, "Enum16"): + return parseEnum(name, chType) + case strings.HasPrefix(chType, "Decimal"): + return parseDecimal(name, chType) + case strings.HasPrefix(chType, "SimpleAggregateFunction"): + if nestedType, err := getNestedType(chType, "SimpleAggregateFunction"); err != nil { + return nil, err + } else { + return Factory(name, nestedType, timezone) + } + case strings.HasPrefix(chType, "Tuple"): + return parseTuple(name, chType, timezone) + } + return nil, fmt.Errorf("column: unhandled type %v", chType) +} + +func getNestedType(chType string, wrapType string) (string, error) { + prefixLen := len(wrapType) + 1 + suffixLen := 1 + + if len(chType) > prefixLen+suffixLen { + nested := strings.Split(chType[prefixLen:len(chType)-suffixLen], ",") + if len(nested) == 2 { + return strings.TrimSpace(nested[1]), nil + } + + if len(nested) == 3 { + return strings.TrimSpace(strings.Join(nested[1:], ",")), nil + } + } + + return "", fmt.Errorf("column: invalid %s type (%s)", wrapType, chType) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/common.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/common.go new file mode 100644 index 0000000000..0583eeea91 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/common.go @@ -0,0 +1,115 @@ +package column + +import ( + "fmt" + "net" + "reflect" + "time" +) + +type ErrUnexpectedType struct { + Column Column + T interface{} +} + +func (err *ErrUnexpectedType) Error() string { + return fmt.Sprintf("%s: unexpected type %T", err.Column, err.T) +} + +var columnBaseTypes = map[interface{}]reflect.Value{ + int8(0): reflect.ValueOf(int8(0)), + int16(0): reflect.ValueOf(int16(0)), + int32(0): reflect.ValueOf(int32(0)), + int64(0): reflect.ValueOf(int64(0)), + uint8(0): reflect.ValueOf(uint8(0)), + uint16(0): reflect.ValueOf(uint16(0)), + uint32(0): reflect.ValueOf(uint32(0)), + uint64(0): reflect.ValueOf(uint64(0)), + float32(0): reflect.ValueOf(float32(0)), + float64(0): reflect.ValueOf(float64(0)), + string(""): reflect.ValueOf(string("")), + time.Time{}: reflect.ValueOf(time.Time{}), + IPv4{}: reflect.ValueOf(net.IPv4zero), + IPv6{}: reflect.ValueOf(net.IPv6unspecified), +} + +type ptrTo uint8 + +const ( + ptrInt8T ptrTo = iota + ptrInt16T + ptrInt32T + ptrInt64T + ptrUInt8T + ptrUInt16T + ptrUInt32T + ptrUInt64T + ptrFloat32 + ptrFloat64 + ptrString + ptrTime + ptrIPv4 + ptrIPv6 +) + +var arrayBaseTypes = map[interface{}]reflect.Type{ + int8(0): reflect.ValueOf(int8(0)).Type(), + int16(0): reflect.ValueOf(int16(0)).Type(), + int32(0): reflect.ValueOf(int32(0)).Type(), + int64(0): reflect.ValueOf(int64(0)).Type(), + uint8(0): reflect.ValueOf(uint8(0)).Type(), + uint16(0): reflect.ValueOf(uint16(0)).Type(), + uint32(0): reflect.ValueOf(uint32(0)).Type(), + uint64(0): reflect.ValueOf(uint64(0)).Type(), + float32(0): reflect.ValueOf(float32(0)).Type(), + float64(0): reflect.ValueOf(float64(0)).Type(), + string(""): reflect.ValueOf(string("")).Type(), + time.Time{}: reflect.ValueOf(time.Time{}).Type(), + IPv4{}: reflect.ValueOf(net.IPv4zero).Type(), + IPv6{}: reflect.ValueOf(net.IPv6unspecified).Type(), + + // nullable + ptrInt8T: reflect.PtrTo(reflect.ValueOf(int8(0)).Type()), + ptrInt16T: reflect.PtrTo(reflect.ValueOf(int16(0)).Type()), + ptrInt32T: reflect.PtrTo(reflect.ValueOf(int32(0)).Type()), + ptrInt64T: reflect.PtrTo(reflect.ValueOf(int64(0)).Type()), + ptrUInt8T: reflect.PtrTo(reflect.ValueOf(uint8(0)).Type()), + ptrUInt16T: reflect.PtrTo(reflect.ValueOf(uint16(0)).Type()), + ptrUInt32T: reflect.PtrTo(reflect.ValueOf(uint32(0)).Type()), + ptrUInt64T: reflect.PtrTo(reflect.ValueOf(uint64(0)).Type()), + ptrFloat32: reflect.PtrTo(reflect.ValueOf(float32(0)).Type()), + ptrFloat64: reflect.PtrTo(reflect.ValueOf(float64(0)).Type()), + ptrString: reflect.PtrTo(reflect.ValueOf(string("")).Type()), + ptrTime: reflect.PtrTo(reflect.ValueOf(time.Time{}).Type()), + ptrIPv4: reflect.PtrTo(reflect.ValueOf(net.IPv4zero).Type()), + ptrIPv6: reflect.PtrTo(reflect.ValueOf(net.IPv6unspecified).Type()), +} + +type base struct { + name, chType string + valueOf reflect.Value +} + +func (base *base) Name() string { + return base.name +} + +func (base *base) CHType() string { + return base.chType +} + +func (base *base) ScanType() reflect.Type { + return base.valueOf.Type() +} + +func (base *base) defaultValue() interface{} { + return base.valueOf.Interface() +} + +func (base *base) String() string { + return fmt.Sprintf("%s (%s)", base.name, base.chType) +} + +func (base *base) Depth() int { + return 0 +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/date.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/date.go new file mode 100644 index 0000000000..6dacb45c2d --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/date.go @@ -0,0 +1,84 @@ +package column + +import ( + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Date struct { + base + Timezone *time.Location + offset int64 +} + +func (dt *Date) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + sec, err := decoder.Int16() + if err != nil { + return nil, err + } + return time.Unix(int64(sec)*24*3600-dt.offset, 0).In(dt.Timezone), nil +} + +func (dt *Date) Write(encoder *binary.Encoder, v interface{}) error { + var timestamp int64 + switch value := v.(type) { + case time.Time: + _, offset := value.Zone() + timestamp = value.Unix() + int64(offset) + case int16: + return encoder.Int16(value) + case int32: + timestamp = int64(value) + dt.offset + case uint32: + timestamp = int64(value) + dt.offset + case uint64: + timestamp = int64(value) + dt.offset + case int64: + timestamp = value + dt.offset + case string: + var err error + timestamp, err = dt.parse(value) + if err != nil { + return err + } + + // this relies on Nullable never sending nil values through + case *time.Time: + _, offset := value.Zone() + timestamp = (*value).Unix() + int64(offset) + case *int16: + return encoder.Int16(*value) + case *int32: + timestamp = int64(*value) + dt.offset + case *int64: + timestamp = *value + dt.offset + case *string: + var err error + timestamp, err = dt.parse(*value) + if err != nil { + return err + } + + default: + return &ErrUnexpectedType{ + T: v, + Column: dt, + } + } + + return encoder.Int16(int16(timestamp / 24 / 3600)) +} + +func (dt *Date) parse(value string) (int64, error) { + tv, err := time.Parse("2006-01-02", value) + if err != nil { + return 0, err + } + return time.Date( + time.Time(tv).Year(), + time.Time(tv).Month(), + time.Time(tv).Day(), + 0, 0, 0, 0, time.UTC, + ).Unix(), nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/datetime.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/datetime.go new file mode 100644 index 0000000000..3252c83530 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/datetime.go @@ -0,0 +1,87 @@ +package column + +import ( + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type DateTime struct { + base + Timezone *time.Location +} + +func (dt *DateTime) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + sec, err := decoder.Int32() + if err != nil { + return nil, err + } + return time.Unix(int64(sec), 0).In(dt.Timezone), nil +} + +func (dt *DateTime) Write(encoder *binary.Encoder, v interface{}) error { + var timestamp int64 + switch value := v.(type) { + case time.Time: + if !value.IsZero() { + timestamp = value.Unix() + } + case int16: + timestamp = int64(value) + case int32: + timestamp = int64(value) + case uint32: + timestamp = int64(value) + case uint64: + timestamp = int64(value) + case int64: + timestamp = value + case string: + var err error + timestamp, err = dt.parse(value) + if err != nil { + return err + } + + case *time.Time: + if value != nil && !(*value).IsZero() { + timestamp = (*value).Unix() + } + case *int16: + timestamp = int64(*value) + case *int32: + timestamp = int64(*value) + case *int64: + timestamp = *value + case *string: + var err error + timestamp, err = dt.parse(*value) + if err != nil { + return err + } + + default: + return &ErrUnexpectedType{ + T: v, + Column: dt, + } + } + + return encoder.Int32(int32(timestamp)) +} + +func (dt *DateTime) parse(value string) (int64, error) { + tv, err := time.Parse("2006-01-02 15:04:05", value) + if err != nil { + return 0, err + } + return time.Date( + time.Time(tv).Year(), + time.Time(tv).Month(), + time.Time(tv).Day(), + time.Time(tv).Hour(), + time.Time(tv).Minute(), + time.Time(tv).Second(), + 0, time.Local, //use local timzone when insert into clickhouse + ).Unix(), nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/datetime64.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/datetime64.go new file mode 100644 index 0000000000..20657f970a --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/datetime64.go @@ -0,0 +1,100 @@ +package column + +import ( + "math" + "strconv" + "strings" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type DateTime64 struct { + base + Timezone *time.Location +} + +func (dt *DateTime64) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + value, err := decoder.Int64() + if err != nil { + return nil, err + } + + precision, err := dt.getPrecision() + if err != nil { + return nil, err + } + + var nano int64 + if precision < 19 { + nano = value * int64(math.Pow10(9-precision)) + } + + sec := nano / int64(10e8) + nsec := nano - sec*10e8 + + return time.Unix(sec, nsec).In(dt.Timezone), nil +} + +func (dt *DateTime64) Write(encoder *binary.Encoder, v interface{}) error { + var timestamp int64 + switch value := v.(type) { + case time.Time: + if !value.IsZero() { + timestamp = value.UnixNano() + } + case uint64: + timestamp = int64(value) + case int64: + timestamp = value + case string: + var err error + timestamp, err = dt.parse(value) + if err != nil { + return err + } + case *time.Time: + if value != nil && !(*value).IsZero() { + timestamp = (*value).UnixNano() + } + case *int64: + timestamp = *value + case *string: + var err error + timestamp, err = dt.parse(*value) + if err != nil { + return err + } + default: + return &ErrUnexpectedType{ + T: v, + Column: dt, + } + } + + precision, err := dt.getPrecision() + if err != nil { + return err + } + + timestamp = timestamp / int64(math.Pow10(9-precision)) + + return encoder.Int64(timestamp) +} + +func (dt *DateTime64) parse(value string) (int64, error) { + tv, err := time.Parse("2006-01-02 15:04:05.999", value) + if err != nil { + return 0, err + } + return tv.UnixNano(), nil +} + +func (dt *DateTime64) getPrecision() (int, error) { + dtParams := dt.base.chType[11 : len(dt.base.chType)-1] + precision, err := strconv.Atoi(strings.Split(dtParams, ",")[0]) + if err != nil { + return 0, err + } + return precision, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/decimal.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/decimal.go new file mode 100644 index 0000000000..464208eee8 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/decimal.go @@ -0,0 +1,377 @@ +package column + +import ( + b "encoding/binary" + "errors" + "fmt" + "math" + "reflect" + "strconv" + "strings" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +// Table of powers of 10 for fast casting from floating types to decimal type +// representations. +var factors10 = []float64{ + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, + 1e14, 1e15, 1e16, 1e17, 1e18, +} + +// Decimal represents Decimal(P, S) ClickHouse. Decimal is represented as +// integral. Also floating-point types are supported for query parameters. +// +// Since there is no support for int128 in Golang, decimals with precision 19 +// through 38 are represented as 16 little-endian bytes. +type Decimal struct { + base + nobits int // its domain is {32, 64} + precision int + scale int +} + +func (d *Decimal) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + switch d.nobits { + case 32: + return decoder.Int32() + case 64: + return decoder.Int64() + case 128: + return decoder.Decimal128() + default: + return nil, errors.New("unachievable execution path") + } +} + +func (d *Decimal) Write(encoder *binary.Encoder, v interface{}) error { + switch d.nobits { + case 32: + return d.write32(encoder, v) + case 64: + return d.write64(encoder, v) + case 128: + return d.write128(encoder, v) + default: + return errors.New("unachievable execution path") + } +} + +func (d *Decimal) float2int32(floating float64) int32 { + fixed := int32(floating * factors10[d.scale]) + return fixed +} + +func (d *Decimal) float2int64(floating float64) int64 { + fixed := int64(floating * factors10[d.scale]) + return fixed +} + +func (d *Decimal) write32(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int8: + return encoder.Int32(int32(v)) + case int16: + return encoder.Int32(int32(v)) + case int32: + return encoder.Int32(int32(v)) + case int64: + if v > math.MaxInt32 || v < math.MinInt32 { + return errors.New("overflow when narrowing type conversion from int64 to int32") + } + return encoder.Int32(int32(v)) + + case uint8: + return encoder.Int32(int32(v)) + case uint16: + return encoder.Int32(int32(v)) + case uint32: + if v > math.MaxInt32 { + return errors.New("overflow when narrowing type conversion from uint32 to int32") + } + return encoder.Int32(int32(v)) + case uint64: + if v > math.MaxInt32 { + return errors.New("overflow when narrowing type conversion from uint64 to int32") + } + return encoder.Int32(int32(v)) + + case float32: + fixed := d.float2int32(float64(v)) + return encoder.Int32(fixed) + case float64: + fixed := d.float2int32(float64(v)) + return encoder.Int32(fixed) + + // this relies on Nullable never sending nil values through + case *int8: + return encoder.Int32(int32(*v)) + case *int16: + return encoder.Int32(int32(*v)) + case *int32: + return encoder.Int32(int32(*v)) + case *int64: + if *v > math.MaxInt32 || *v < math.MinInt32 { + return errors.New("overflow when narrowing type conversion from int64 to int32") + } + return encoder.Int32(int32(*v)) + + case *uint8: + return encoder.Int32(int32(*v)) + case *uint16: + return encoder.Int32(int32(*v)) + case *uint32: + if *v > math.MaxInt32 { + return errors.New("overflow when narrowing type conversion from uint34 to int32") + } + return encoder.Int32(int32(*v)) + case *uint64: + if *v > math.MaxInt32 { + return errors.New("overflow when narrowing type conversion from uint64 to int32") + } + return encoder.Int32(int32(*v)) + + case *float32: + fixed := d.float2int32(float64(*v)) + return encoder.Int32(fixed) + case *float64: + fixed := d.float2int32(float64(*v)) + return encoder.Int32(fixed) + } + + return &ErrUnexpectedType{ + T: v, + Column: d, + } +} + +func (d *Decimal) write64(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int: + return encoder.Int64(int64(v)) + case int8: + return encoder.Int64(int64(v)) + case int16: + return encoder.Int64(int64(v)) + case int32: + return encoder.Int64(int64(v)) + case int64: + return encoder.Int64(int64(v)) + + case uint8: + return encoder.Int64(int64(v)) + case uint16: + return encoder.Int64(int64(v)) + case uint32: + return encoder.Int64(int64(v)) + case uint64: + if v > math.MaxInt64 { + return errors.New("overflow when narrowing type conversion from uint64 to int64") + } + return encoder.Int64(int64(v)) + + case float32: + fixed := d.float2int64(float64(v)) + return encoder.Int64(fixed) + case float64: + fixed := d.float2int64(float64(v)) + return encoder.Int64(fixed) + + // this relies on Nullable never sending nil values through + case *int: + return encoder.Int64(int64(*v)) + case *int8: + return encoder.Int64(int64(*v)) + case *int16: + return encoder.Int64(int64(*v)) + case *int32: + return encoder.Int64(int64(*v)) + case *int64: + return encoder.Int64(int64(*v)) + + case *uint8: + return encoder.Int64(int64(*v)) + case *uint16: + return encoder.Int64(int64(*v)) + case *uint32: + return encoder.Int64(int64(*v)) + case *uint64: + if *v > math.MaxInt64 { + return errors.New("overflow when narrowing type conversion from uint64 to int64") + } + return encoder.Int64(int64(*v)) + + case *float32: + fixed := d.float2int64(float64(*v)) + return encoder.Int64(fixed) + case *float64: + fixed := d.float2int64(float64(*v)) + return encoder.Int64(fixed) + } + + return &ErrUnexpectedType{ + T: v, + Column: d, + } +} + +// Turns an int64 into 16 little-endian bytes. +func int64ToDecimal128(v int64) []byte { + bytes := make([]byte, 16) + b.LittleEndian.PutUint64(bytes[:8], uint64(v)) + sign := 0 + if v < 0 { + sign = -1 + } + b.LittleEndian.PutUint64(bytes[8:], uint64(sign)) + return bytes +} + +// Turns a uint64 into 16 little-endian bytes. +func uint64ToDecimal128(v uint64) []byte { + bytes := make([]byte, 16) + b.LittleEndian.PutUint64(bytes[:8], uint64(v)) + return bytes +} + +func (d *Decimal) write128(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int: + return encoder.Decimal128(int64ToDecimal128(int64(v))) + case int8: + return encoder.Decimal128(int64ToDecimal128(int64(v))) + case int16: + return encoder.Decimal128(int64ToDecimal128(int64(v))) + case int32: + return encoder.Decimal128(int64ToDecimal128(int64(v))) + case int64: + return encoder.Decimal128(int64ToDecimal128(v)) + + case uint8: + return encoder.Decimal128(uint64ToDecimal128(uint64(v))) + case uint16: + return encoder.Decimal128(uint64ToDecimal128(uint64(v))) + case uint32: + return encoder.Decimal128(uint64ToDecimal128(uint64(v))) + case uint64: + return encoder.Decimal128(uint64ToDecimal128(v)) + + case float32: + fixed := d.float2int64(float64(v)) + return encoder.Decimal128(int64ToDecimal128(fixed)) + case float64: + fixed := d.float2int64(float64(v)) + return encoder.Decimal128(int64ToDecimal128(fixed)) + + case []byte: + if len(v) != 16 { + return errors.New("expected 16 bytes") + } + return encoder.Decimal128(v) + + // this relies on Nullable never sending nil values through + case *int: + return encoder.Decimal128(int64ToDecimal128(int64(*v))) + case *int8: + return encoder.Decimal128(int64ToDecimal128(int64(*v))) + case *int16: + return encoder.Decimal128(int64ToDecimal128(int64(*v))) + case *int32: + return encoder.Decimal128(int64ToDecimal128(int64(*v))) + case *int64: + return encoder.Decimal128(int64ToDecimal128(*v)) + + case *uint8: + return encoder.Decimal128(uint64ToDecimal128(uint64(*v))) + case *uint16: + return encoder.Decimal128(uint64ToDecimal128(uint64(*v))) + case *uint32: + return encoder.Decimal128(uint64ToDecimal128(uint64(*v))) + case *uint64: + return encoder.Decimal128(uint64ToDecimal128(*v)) + + case *float32: + fixed := d.float2int64(float64(*v)) + return encoder.Decimal128(int64ToDecimal128(fixed)) + case *float64: + fixed := d.float2int64(float64(*v)) + return encoder.Decimal128(int64ToDecimal128(fixed)) + + case *[]byte: + if len(*v) != 16 { + return errors.New("expected 16 bytes") + } + return encoder.Decimal128(*v) + } + + return &ErrUnexpectedType{ + T: v, + Column: d, + } +} + +func parseDecimal(name, chType string) (Column, error) { + switch { + case len(chType) < 12: + fallthrough + case !strings.HasPrefix(chType, "Decimal"): + fallthrough + case chType[7] != '(': + fallthrough + case chType[len(chType)-1] != ')': + return nil, fmt.Errorf("invalid Decimal format: '%s'", chType) + } + + var params = strings.Split(chType[8:len(chType)-1], ",") + + if len(params) != 2 { + return nil, fmt.Errorf("invalid Decimal format: '%s'", chType) + } + + params[0] = strings.TrimSpace(params[0]) + params[1] = strings.TrimSpace(params[1]) + + var err error + var decimal = &Decimal{ + base: base{ + name: name, + chType: chType, + }, + } + + if decimal.precision, err = strconv.Atoi(params[0]); err != nil { + return nil, fmt.Errorf("'%s' is not Decimal type: %s", chType, err) + } else if decimal.precision < 1 { + return nil, errors.New("wrong precision of Decimal type") + } + + if decimal.scale, err = strconv.Atoi(params[1]); err != nil { + return nil, fmt.Errorf("'%s' is not Decimal type: %s", chType, err) + } else if decimal.scale < 0 || decimal.scale > decimal.precision { + return nil, errors.New("wrong scale of Decimal type") + } + + switch { + case decimal.precision <= 9: + decimal.nobits = 32 + decimal.valueOf = columnBaseTypes[int32(0)] + case decimal.precision <= 18: + decimal.nobits = 64 + decimal.valueOf = columnBaseTypes[int64(0)] + case decimal.precision <= 38: + decimal.nobits = 128 + decimal.valueOf = reflect.ValueOf([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) + default: + return nil, errors.New("precision of Decimal exceeds max bound") + } + + return decimal, nil +} + +func (d *Decimal) GetPrecision() int { + return d.precision +} + +func (d *Decimal) GetScale() int { + return d.scale +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/enum.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/enum.go new file mode 100644 index 0000000000..59a8d7073c --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/enum.go @@ -0,0 +1,175 @@ +package column + +import ( + "fmt" + "strconv" + "strings" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Enum struct { + iv map[string]interface{} + vi map[interface{}]string + base + baseType interface{} +} + +func (enum *Enum) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + var ( + err error + ident interface{} + ) + switch enum.baseType.(type) { + case int16: + if ident, err = decoder.Int16(); err != nil { + return nil, err + } + default: + if ident, err = decoder.Int8(); err != nil { + return nil, err + } + } + if ident, found := enum.vi[ident]; found || isNull { + return ident, nil + } + return nil, fmt.Errorf("invalid Enum value: %v", ident) +} + +func (enum *Enum) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case string: + return enum.encodeFromString(v, encoder) + case uint8: + if _, ok := enum.baseType.(int8); ok { + return encoder.Int8(int8(v)) + } + case int8: + if _, ok := enum.baseType.(int8); ok { + return encoder.Int8(v) + } + case uint16: + if _, ok := enum.baseType.(int16); ok { + return encoder.Int16(int16(v)) + } + case int16: + if _, ok := enum.baseType.(int16); ok { + return encoder.Int16(v) + } + case int64: + switch enum.baseType.(type) { + case int8: + return encoder.Int8(int8(v)) + case int16: + return encoder.Int16(int16(v)) + } + // nullable enums + case *string: + return enum.encodeFromString(*v, encoder) + case *uint8: + if _, ok := enum.baseType.(int8); ok { + return encoder.Int8(int8(*v)) + } + case *int8: + if _, ok := enum.baseType.(int8); ok { + return encoder.Int8(*v) + } + case *uint16: + if _, ok := enum.baseType.(int16); ok { + return encoder.Int16(int16(*v)) + } + case *int16: + if _, ok := enum.baseType.(int16); ok { + return encoder.Int16(*v) + } + case *int64: + switch enum.baseType.(type) { + case int8: + return encoder.Int8(int8(*v)) + case int16: + return encoder.Int16(int16(*v)) + } + } + return &ErrUnexpectedType{ + T: v, + Column: enum, + } +} + +func (enum *Enum) encodeFromString(v string, encoder *binary.Encoder) error { + ident, found := enum.iv[v] + if !found { + return fmt.Errorf("invalid Enum ident: %s", v) + } + switch ident := ident.(type) { + case int8: + return encoder.Int8(ident) + case int16: + return encoder.Int16(ident) + default: + return &ErrUnexpectedType{ + T: ident, + Column: enum, + } + } +} + +func (enum *Enum) defaultValue() interface{} { + return enum.baseType +} + +func parseEnum(name, chType string) (*Enum, error) { + var ( + data string + isEnum16 bool + ) + if len(chType) < 8 { + return nil, fmt.Errorf("invalid Enum format: %s", chType) + } + switch { + case strings.HasPrefix(chType, "Enum8"): + data = chType[6:] + case strings.HasPrefix(chType, "Enum16"): + data = chType[7:] + isEnum16 = true + default: + return nil, fmt.Errorf("'%s' is not Enum type", chType) + } + enum := Enum{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[string("")], + }, + iv: make(map[string]interface{}), + vi: make(map[interface{}]string), + } + for _, block := range strings.Split(data[:len(data)-1], ",") { + parts := strings.Split(block, "=") + if len(parts) != 2 { + return nil, fmt.Errorf("invalid Enum format: %s", chType) + } + var ( + ident = strings.TrimSpace(parts[0]) + value, err = strconv.ParseInt(strings.TrimSpace(parts[1]), 10, 16) + ) + if err != nil { + return nil, fmt.Errorf("invalid Enum value: %v", chType) + } + { + var ( + ident = ident[1 : len(ident)-1] + value interface{} = int16(value) + ) + if !isEnum16 { + value = int8(value.(int16)) + } + if enum.baseType == nil { + enum.baseType = value + } + enum.iv[ident] = value + enum.vi[value] = ident + } + } + return &enum, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/fixed_string.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/fixed_string.go new file mode 100644 index 0000000000..75135f7b23 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/fixed_string.go @@ -0,0 +1,71 @@ +package column + +import ( + "encoding" + "fmt" + "reflect" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type FixedString struct { + base + len int + scanType reflect.Type +} + +func (str *FixedString) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Fixed(str.len) + if err != nil { + return "", err + } + return string(v), nil +} + +func (str *FixedString) Write(encoder *binary.Encoder, v interface{}) error { + var fixedString []byte + switch v := v.(type) { + case string: + fixedString = binary.Str2Bytes(v) + case []byte: + fixedString = v + case encoding.BinaryMarshaler: + bytes, err := v.MarshalBinary() + if err != nil { + return err + } + fixedString = bytes + default: + return &ErrUnexpectedType{ + T: v, + Column: str, + } + } + switch { + case len(fixedString) > str.len: + return fmt.Errorf("too large value '%s' (expected %d, got %d)", fixedString, str.len, len(fixedString)) + case len(fixedString) < str.len: + tmp := make([]byte, str.len) + copy(tmp, fixedString) + fixedString = tmp + } + if _, err := encoder.Write(fixedString); err != nil { + return err + } + return nil +} + +func parseFixedString(name, chType string) (*FixedString, error) { + var strLen int + if _, err := fmt.Sscanf(chType, "FixedString(%d)", &strLen); err != nil { + return nil, err + } + return &FixedString{ + base: base{ + name: name, + chType: chType, + valueOf: columnBaseTypes[string("")], + }, + len: strLen, + }, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float32.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float32.go new file mode 100644 index 0000000000..477a6a1a39 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float32.go @@ -0,0 +1,35 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Float32 struct{ base } + +func (Float32) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Float32() + if err != nil { + return float32(0), err + } + return v, nil +} + +func (float *Float32) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case float32: + return encoder.Float32(v) + case float64: + return encoder.Float32(float32(v)) + + // this relies on Nullable never sending nil values through + case *float32: + return encoder.Float32(*v) + case *float64: + return encoder.Float32(float32(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: float, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float64.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float64.go new file mode 100644 index 0000000000..2f8454004b --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/float64.go @@ -0,0 +1,35 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Float64 struct{ base } + +func (Float64) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Float64() + if err != nil { + return float64(0), err + } + return v, nil +} + +func (float *Float64) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case float32: + return encoder.Float64(float64(v)) + case float64: + return encoder.Float64(v) + + // this relies on Nullable never sending nil values through + case *float32: + return encoder.Float64(float64(*v)) + case *float64: + return encoder.Float64(*v) + } + + return &ErrUnexpectedType{ + T: v, + Column: float, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int16.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int16.go new file mode 100644 index 0000000000..0b2d167dad --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int16.go @@ -0,0 +1,39 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Int16 struct{ base } + +func (Int16) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Int16() + if err != nil { + return int16(0), err + } + return v, nil +} + +func (i *Int16) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int16: + return encoder.Int16(v) + case int64: + return encoder.Int16(int16(v)) + case int: + return encoder.Int16(int16(v)) + + // this relies on Nullable never sending nil values through + case *int16: + return encoder.Int16(*v) + case *int64: + return encoder.Int16(int16(*v)) + case *int: + return encoder.Int16(int16(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: i, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int32.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int32.go new file mode 100644 index 0000000000..34328e3043 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int32.go @@ -0,0 +1,39 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Int32 struct{ base } + +func (Int32) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Int32() + if err != nil { + return int32(0), err + } + return v, nil +} + +func (i *Int32) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int32: + return encoder.Int32(v) + case int64: + return encoder.Int32(int32(v)) + case int: + return encoder.Int32(int32(v)) + + // this relies on Nullable never sending nil values through + case *int32: + return encoder.Int32(*v) + case *int64: + return encoder.Int32(int32(*v)) + case *int: + return encoder.Int32(int32(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: i, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int64.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int64.go new file mode 100644 index 0000000000..fa627f0cb8 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int64.go @@ -0,0 +1,40 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Int64 struct{ base } + +func (Int64) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Int64() + if err != nil { + return int64(0), err + } + return v, nil +} + +func (i *Int64) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int: + return encoder.Int64(int64(v)) + case int64: + return encoder.Int64(v) + case []byte: + if _, err := encoder.Write(v); err != nil { + return err + } + return nil + + // this relies on Nullable never sending nil values through + case *int: + return encoder.Int64(int64(*v)) + case *int64: + return encoder.Int64(*v) + } + + return &ErrUnexpectedType{ + T: v, + Column: i, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int8.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int8.go new file mode 100644 index 0000000000..aa36bee2bf --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/int8.go @@ -0,0 +1,49 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Int8 struct{ base } + +func (Int8) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Int8() + if err != nil { + return int8(0), err + } + return v, nil +} + +func (i *Int8) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case int8: + return encoder.Int8(v) + case int64: + return encoder.Int8(int8(v)) + case int: + return encoder.Int8(int8(v)) + case bool: + if v { + return encoder.Int8(int8(1)) + } + return encoder.Int8(int8(0)) + + // this relies on Nullable never sending nil values through + case *int8: + return encoder.Int8(*v) + case *int64: + return encoder.Int8(int8(*v)) + case *int: + return encoder.Int8(int8(*v)) + case *bool: + if *v { + return encoder.Int8(int8(1)) + } + return encoder.Int8(int8(0)) + } + + return &ErrUnexpectedType{ + T: v, + Column: i, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ip.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ip.go new file mode 100644 index 0000000000..03056d7c54 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ip.go @@ -0,0 +1,84 @@ +/* +IP type supporting for clickhouse as FixedString(16) +*/ + +package column + +import ( + "database/sql/driver" + "errors" + "net" + "strings" +) + +var ( + errInvalidScanType = errors.New("Invalid scan types") + errInvalidScanValue = errors.New("Invalid scan value") +) + +// IP column type +type IP net.IP + +// Value implements the driver.Valuer interface, json field interface +// Alignment on the right side +func (ip IP) Value() (driver.Value, error) { + return ip.MarshalBinary() +} + +func (ip IP) MarshalBinary() ([]byte, error) { + if len(ip) < 16 { + var ( + buff = make([]byte, 16) + j = 0 + ) + for i := 16 - len(ip); i < 16; i++ { + buff[i] = ip[j] + j++ + } + for i := 0; i < 16-len(ip); i++ { + buff[i] = '\x00' + } + if len(ip) == 4 { + buff[11] = '\xff' + buff[10] = '\xff' + } + return buff, nil + } + return []byte(ip), nil +} + +// Scan implements the driver.Valuer interface, json field interface +func (ip *IP) Scan(value interface{}) (err error) { + switch v := value.(type) { + case []byte: + if len(v) == 4 || len(v) == 16 { + *ip = IP(v) + } else { + err = errInvalidScanValue + } + case string: + if v == "" { + err = errInvalidScanValue + return + } + if (len(v) == 4 || len(v) == 16) && !strings.Contains(v, ".") && !strings.Contains(v, ":"){ + *ip = IP([]byte(v)) + return + } + if strings.Contains(v, ":") { + *ip = IP(net.ParseIP(v)) + return + } + *ip = IP(net.ParseIP(v).To4()) + case net.IP: + *ip = IP(v) + default: + err = errInvalidScanType + } + return +} + +// String implements the fmt.Stringer interface +func (ip IP) String() string { + return net.IP(ip).String() +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ipv4.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ipv4.go new file mode 100644 index 0000000000..eaac52c6da --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ipv4.go @@ -0,0 +1,54 @@ +package column + +import ( + "net" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type IPv4 struct { + base +} + +func (*IPv4) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Fixed(4) + if err != nil { + return nil, err + } + return net.IPv4(v[3], v[2], v[1], v[0]), nil +} + +func (ip *IPv4) Write(encoder *binary.Encoder, v interface{}) error { + var netIP net.IP + switch v.(type) { + case string: + netIP = net.ParseIP(v.(string)) + case net.IP: + netIP = v.(net.IP) + case *net.IP: + netIP = *(v.(*net.IP)) + default: + return &ErrUnexpectedType{ + T: v, + Column: ip, + } + } + + if netIP == nil { + return &ErrUnexpectedType{ + T: v, + Column: ip, + } + } + ip4 := netIP.To4() + if ip4 == nil { + return &ErrUnexpectedType{ + T: v, + Column: ip, + } + } + if _, err := encoder.Write([]byte{ip4[3], ip4[2], ip4[1], ip4[0]}); err != nil { + return err + } + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ipv6.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ipv6.go new file mode 100644 index 0000000000..0fa9f8a9f8 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/ipv6.go @@ -0,0 +1,47 @@ +package column + +import ( + "net" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type IPv6 struct { + base +} + +func (*IPv6) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.Fixed(16) + if err != nil { + return nil, err + } + return net.IP(v), nil +} + +func (ip *IPv6) Write(encoder *binary.Encoder, v interface{}) error { + var netIP net.IP + switch v.(type) { + case string: + netIP = net.ParseIP(v.(string)) + case net.IP: + netIP = v.(net.IP) + case *net.IP: + netIP = *(v.(*net.IP)) + default: + return &ErrUnexpectedType{ + T: v, + Column: ip, + } + } + + if netIP == nil { + return &ErrUnexpectedType{ + T: v, + Column: ip, + } + } + if _, err := encoder.Write([]byte(netIP.To16())); err != nil { + return err + } + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/nullable.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/nullable.go new file mode 100644 index 0000000000..9dd88b546a --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/nullable.go @@ -0,0 +1,96 @@ +package column + +import ( + "fmt" + "reflect" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type Nullable struct { + base + column Column +} + +func (null *Nullable) ScanType() reflect.Type { + return reflect.PtrTo(null.column.ScanType()) +} + +func (null *Nullable) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + return null.column.Read(decoder, isNull) +} + +func (null *Nullable) Write(encoder *binary.Encoder, v interface{}) error { + return nil +} + +func (null *Nullable) ReadNull(decoder *binary.Decoder, rows int) (_ []interface{}, err error) { + var ( + isNull byte + value interface{} + nulls = make([]byte, rows) + values = make([]interface{}, rows) + ) + for i := 0; i < rows; i++ { + if isNull, err = decoder.ReadByte(); err != nil { + return nil, err + } + nulls[i] = isNull + } + for i, isNull := range nulls { + switch value, err = null.column.Read(decoder, isNull != 0); true { + case err != nil: + return nil, err + case isNull == 0: + values[i] = value + default: + values[i] = nil + } + } + return values, nil +} +func (null *Nullable) WriteNull(nulls, encoder *binary.Encoder, v interface{}) error { + if isNil(v) { + if _, err := nulls.Write([]byte{1}); err != nil { + return err + } + return null.column.Write(encoder, null.column.defaultValue()) + } + if _, err := nulls.Write([]byte{0}); err != nil { + return err + } + return null.column.Write(encoder, v) +} + +func parseNullable(name, chType string, timezone *time.Location) (*Nullable, error) { + if len(chType) < 14 { + return nil, fmt.Errorf("invalid Nullable column type: %s", chType) + } + column, err := Factory(name, chType[9:][:len(chType)-10], timezone) + if err != nil { + return nil, fmt.Errorf("Nullable(T): %v", err) + } + return &Nullable{ + base: base{ + name: name, + chType: chType, + }, + column: column, + }, nil +} + +func (null *Nullable) GetColumn() Column { + return null.column +} + +func isNil(v interface{}) bool { + if v == nil { + return true + } + switch val := reflect.ValueOf(v); val.Type().Kind() { + case reflect.Array, reflect.Chan, reflect.Map, reflect.Ptr, reflect.Slice: + return val.IsNil() + } + return false +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/nullable_appender.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/nullable_appender.go new file mode 100644 index 0000000000..a768026211 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/nullable_appender.go @@ -0,0 +1,173 @@ + +// DANGER! This code was autogenerated from template by clickhouse-go/lib/codegen/nullable_appender. +// You shouldn't change it manually. +// For more info check clickhouse-go/lib/codegen/nullable_appender/main.go + +package column + +import ( + "fmt" + "net" + "reflect" + "time" +) + +var nullableAppender = map[string]func(v interface{}, slice reflect.Value) (reflect.Value, error){ + + "*int8": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(int8) + if !ok { + return slice, fmt.Errorf("cannot assert to type int8") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *int8 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*int16": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(int16) + if !ok { + return slice, fmt.Errorf("cannot assert to type int16") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *int16 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*int32": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(int32) + if !ok { + return slice, fmt.Errorf("cannot assert to type int32") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *int32 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*int64": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(int64) + if !ok { + return slice, fmt.Errorf("cannot assert to type int64") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *int64 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*uint8": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(uint8) + if !ok { + return slice, fmt.Errorf("cannot assert to type uint8") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *uint8 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*uint16": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(uint16) + if !ok { + return slice, fmt.Errorf("cannot assert to type uint16") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *uint16 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*uint32": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(uint32) + if !ok { + return slice, fmt.Errorf("cannot assert to type uint32") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *uint32 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*uint64": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(uint64) + if !ok { + return slice, fmt.Errorf("cannot assert to type uint64") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *uint64 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*float32": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(float32) + if !ok { + return slice, fmt.Errorf("cannot assert to type float32") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *float32 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*float64": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(float64) + if !ok { + return slice, fmt.Errorf("cannot assert to type float64") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *float64 + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*string": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(string) + if !ok { + return slice, fmt.Errorf("cannot assert to type string") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *string + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*time.Time": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(time.Time) + if !ok { + return slice, fmt.Errorf("cannot assert to type time.Time") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *time.Time + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + + "*net.IP": func(v interface{}, slice reflect.Value) (reflect.Value, error) { + if v != nil { + v, ok := v.(net.IP) + if !ok { + return slice, fmt.Errorf("cannot assert to type net.IP") + } + return reflect.Append(slice, reflect.ValueOf(&v)), nil + } + var vNil *net.IP + return reflect.Append(slice, reflect.ValueOf(vNil)), nil + }, + +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/string.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/string.go new file mode 100644 index 0000000000..a190660fa5 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/string.go @@ -0,0 +1,35 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type String struct{ base } + +func (String) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.String() + if err != nil { + return "", err + } + return v, nil +} + +func (str *String) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case string: + return encoder.String(v) + case []byte: + return encoder.RawString(v) + + // this relies on Nullable never sending nil values through + case *string: + return encoder.String(*v) + case *[]byte: + return encoder.RawString(*v) + } + + return &ErrUnexpectedType{ + T: v, + Column: str, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/tuple.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/tuple.go new file mode 100644 index 0000000000..00578a6e2c --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/tuple.go @@ -0,0 +1,110 @@ +package column + +import ( + "fmt" + "github.com/ClickHouse/clickhouse-go/lib/binary" + "reflect" + "strconv" + "time" +) + +type Tuple struct { + base + columns []Column +} + +func (tuple *Tuple) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + return nil, fmt.Errorf("do not use Read method for Tuple(T) column") +} + +func (tuple *Tuple) ReadTuple(decoder *binary.Decoder, rows int) ([]interface{}, error) { + var values = make([][]interface{}, rows) + + for _, c := range tuple.columns { + + switch column := c.(type) { + case *Array: + cols, err := column.ReadArray(decoder, rows) + if err != nil { + return nil, err + } + for i := 0; i < rows; i++ { + values[i] = append(values[i], cols[i]) + } + + case *Nullable: + cols, err := column.ReadNull(decoder, rows) + if err != nil { + return nil, err + } + for i := 0; i < rows; i++ { + values[i] = append(values[i], cols[i]) + } + + case *Tuple: + cols, err := column.ReadTuple(decoder, rows) + if err != nil { + return nil, err + } + for i := 0; i < rows; i++ { + values[i] = append(values[i], cols[i]) + } + + default: + for i := 0; i < rows; i++ { + value, err := c.Read(decoder, false) + if err != nil { + return nil, err + } + values[i] = append(values[i], value) + } + } + } + + var ret = make([]interface{}, rows) + for i := range values { + ret[i] = values[i] + } + + return ret, nil +} + +func (tuple *Tuple) Write(encoder *binary.Encoder, v interface{}) (err error) { + return fmt.Errorf("unsupported Tuple(T) type [%T]", v) +} + +func parseTuple(name, chType string, timezone *time.Location) (Column, error) { + var columnType = chType + + chType = chType[6 : len(chType)-1] + var types []string + var last, diff int + for i, b := range chType + "," { + if b == '(' { + diff++ + } else if b == ')' { + diff-- + } else if b == ',' && diff == 0 { + types = append(types, chType[last:i]) + last = i + 2 + } + } + + var columns = make([]Column, 0, len(types)) + for i, chType := range types { + column, err := Factory(name+"."+strconv.Itoa(i+1), chType, timezone) + if err != nil { + return nil, fmt.Errorf("%s: %v", chType, err) + } + columns = append(columns, column) + } + + return &Tuple{ + base: base{ + name: name, + chType: columnType, + valueOf: reflect.ValueOf([]interface{}{}), + }, + columns: columns, + }, nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint16.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint16.go new file mode 100644 index 0000000000..cf761efbcc --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint16.go @@ -0,0 +1,43 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type UInt16 struct{ base } + +func (UInt16) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.UInt16() + if err != nil { + return uint16(0), err + } + return v, nil +} + +func (u *UInt16) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case uint16: + return encoder.UInt16(v) + case int64: + return encoder.UInt16(uint16(v)) + case uint64: + return encoder.UInt16(uint16(v)) + case int: + return encoder.UInt16(uint16(v)) + + // this relies on Nullable never sending nil values through + case *uint16: + return encoder.UInt16(*v) + case *int64: + return encoder.UInt16(uint16(*v)) + case *uint64: + return encoder.UInt16(uint16(*v)) + case *int: + return encoder.UInt16(uint16(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: u, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint32.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint32.go new file mode 100644 index 0000000000..f5f72f5f16 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint32.go @@ -0,0 +1,43 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type UInt32 struct{ base } + +func (UInt32) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.UInt32() + if err != nil { + return uint32(0), err + } + return v, nil +} + +func (u *UInt32) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case uint32: + return encoder.UInt32(v) + case uint64: + return encoder.UInt32(uint32(v)) + case int64: + return encoder.UInt32(uint32(v)) + case int: + return encoder.UInt32(uint32(v)) + + // this relies on Nullable never sending nil values through + case *uint64: + return encoder.UInt32(uint32(*v)) + case *uint32: + return encoder.UInt32(*v) + case *int64: + return encoder.UInt32(uint32(*v)) + case *int: + return encoder.UInt32(uint32(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: u, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint64.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint64.go new file mode 100644 index 0000000000..09261e0106 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint64.go @@ -0,0 +1,44 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type UInt64 struct{ base } + +func (UInt64) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.UInt64() + if err != nil { + return uint64(0), err + } + return v, nil +} + +func (u *UInt64) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case []byte: + if _, err := encoder.Write(v); err != nil { + return err + } + return nil + case uint64: + return encoder.UInt64(v) + case int64: + return encoder.UInt64(uint64(v)) + case int: + return encoder.UInt64(uint64(v)) + + // this relies on Nullable never sending nil values through + case *uint64: + return encoder.UInt64(*v) + case *int64: + return encoder.UInt64(uint64(*v)) + case *int: + return encoder.UInt64(uint64(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: u, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint8.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint8.go new file mode 100644 index 0000000000..8af493e7a0 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uint8.go @@ -0,0 +1,47 @@ +package column + +import ( + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type UInt8 struct{ base } + +func (UInt8) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + v, err := decoder.UInt8() + if err != nil { + return uint8(0), err + } + return v, nil +} + +func (u *UInt8) Write(encoder *binary.Encoder, v interface{}) error { + switch v := v.(type) { + case bool: + return encoder.Bool(v) + case uint8: + return encoder.UInt8(v) + case int64: + return encoder.UInt8(uint8(v)) + case uint64: + return encoder.UInt8(uint8(v)) + case int: + return encoder.UInt8(uint8(v)) + + // this relies on Nullable never sending nil values through + case *bool: + return encoder.Bool(*v) + case *uint8: + return encoder.UInt8(*v) + case *int64: + return encoder.UInt8(uint8(*v)) + case *uint64: + return encoder.UInt8(uint8(*v)) + case *int: + return encoder.UInt8(uint8(*v)) + } + + return &ErrUnexpectedType{ + T: v, + Column: u, + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uuid.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uuid.go new file mode 100644 index 0000000000..f778acc923 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/column/uuid.go @@ -0,0 +1,139 @@ +package column + +import ( + "encoding/hex" + "errors" + "fmt" + "reflect" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +const ( + UUIDLen = 16 + NullUUID = "00000000-0000-0000-0000-000000000000" +) + +var ErrInvalidUUIDFormat = errors.New("invalid UUID format") + +type UUID struct { + base + scanType reflect.Type +} + +func (*UUID) Read(decoder *binary.Decoder, isNull bool) (interface{}, error) { + src, err := decoder.Fixed(UUIDLen) + if err != nil { + return "", err + } + + src = swap(src) + + var uuid [36]byte + { + hex.Encode(uuid[:], src[:4]) + uuid[8] = '-' + hex.Encode(uuid[9:13], src[4:6]) + uuid[13] = '-' + hex.Encode(uuid[14:18], src[6:8]) + uuid[18] = '-' + hex.Encode(uuid[19:23], src[8:10]) + uuid[23] = '-' + hex.Encode(uuid[24:], src[10:]) + } + return string(uuid[:]), nil +} + +func (u *UUID) Write(encoder *binary.Encoder, v interface{}) (err error) { + var uuid []byte + switch v := v.(type) { + case string: + if uuid, err = uuid2bytes(v); err != nil { + return err + } + case []byte: + if len(v) != UUIDLen { + return fmt.Errorf("invalid raw UUID len '%s' (expected %d, got %d)", uuid, UUIDLen, len(uuid)) + } + uuid = make([]byte, 16) + copy(uuid, v) + default: + return &ErrUnexpectedType{ + T: v, + Column: u, + } + } + + uuid = swap(uuid) + + if _, err := encoder.Write(uuid); err != nil { + return err + } + return nil +} + +func swap(src []byte) []byte { + _ = src[15] + src[0], src[7] = src[7], src[0] + src[1], src[6] = src[6], src[1] + src[2], src[5] = src[5], src[2] + src[3], src[4] = src[4], src[3] + src[8], src[15] = src[15], src[8] + src[9], src[14] = src[14], src[9] + src[10], src[13] = src[13], src[10] + src[11], src[12] = src[12], src[11] + return src +} + +func uuid2bytes(str string) ([]byte, error) { + var uuid [16]byte + strLength := len(str) + if strLength == 0 { + str = NullUUID + } else if strLength != 36 { + return nil, ErrInvalidUUIDFormat + } + if str[8] != '-' || str[13] != '-' || str[18] != '-' || str[23] != '-' { + return nil, ErrInvalidUUIDFormat + } + for i, x := range [16]int{ + 0, 2, 4, 6, + 9, 11, 14, 16, + 19, 21, 24, 26, + 28, 30, 32, 34, + } { + if v, ok := xtob(str[x], str[x+1]); !ok { + return nil, ErrInvalidUUIDFormat + } else { + uuid[i] = v + } + } + return uuid[:], nil +} + +// xvalues returns the value of a byte as a hexadecimal digit or 255. +var xvalues = [256]byte{ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, + 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, +} + +// xtob converts hex characters x1 and x2 into a byte. +func xtob(x1, x2 byte) (byte, bool) { + b1 := xvalues[x1] + b2 := xvalues[x2] + return (b1 << 4) | b2, b1 != 255 && b2 != 255 +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/data/block.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/block.go new file mode 100644 index 0000000000..d88ee105bd --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/block.go @@ -0,0 +1,326 @@ +package data + +import ( + "bytes" + "database/sql/driver" + "fmt" + "io" + "reflect" + "strings" + + "github.com/ClickHouse/clickhouse-go/lib/binary" + "github.com/ClickHouse/clickhouse-go/lib/column" +) + +type offset [][]int + +type Block struct { + Values [][]interface{} + Columns []column.Column + NumRows uint64 + NumColumns uint64 + offsets []offset + buffers []*buffer + info blockInfo +} + +func (block *Block) Copy() *Block { + return &Block{ + Columns: block.Columns, + NumColumns: block.NumColumns, + info: block.info, + } +} + +func (block *Block) ColumnNames() []string { + names := make([]string, 0, len(block.Columns)) + for _, column := range block.Columns { + names = append(names, column.Name()) + } + return names +} + +func (block *Block) Read(serverInfo *ServerInfo, decoder *binary.Decoder) (err error) { + if serverInfo.Revision > 0 { + if err = block.info.read(decoder); err != nil { + return err + } + } + + if block.NumColumns, err = decoder.Uvarint(); err != nil { + return err + } + if block.NumRows, err = decoder.Uvarint(); err != nil { + return err + } + block.Values = make([][]interface{}, block.NumColumns) + if block.NumRows > 10 { + for i := 0; i < int(block.NumColumns); i++ { + block.Values[i] = make([]interface{}, 0, block.NumRows) + } + } + for i := 0; i < int(block.NumColumns); i++ { + var ( + value interface{} + columnName string + columnType string + ) + if columnName, err = decoder.String(); err != nil { + return err + } + if columnType, err = decoder.String(); err != nil { + return err + } + c, err := column.Factory(columnName, columnType, serverInfo.Timezone) + if err != nil { + return err + } + block.Columns = append(block.Columns, c) + switch column := c.(type) { + case *column.Array: + if block.Values[i], err = column.ReadArray(decoder, int(block.NumRows)); err != nil { + return err + } + case *column.Nullable: + if block.Values[i], err = column.ReadNull(decoder, int(block.NumRows)); err != nil { + return err + } + case *column.Tuple: + if block.Values[i], err = column.ReadTuple(decoder, int(block.NumRows)); err != nil { + return err + } + default: + for row := 0; row < int(block.NumRows); row++ { + if value, err = column.Read(decoder, false); err != nil { + return err + } + block.Values[i] = append(block.Values[i], value) + } + } + } + return nil +} + +func (block *Block) writeArray(col column.Column, value Value, num, level int) error { + if level > col.Depth() { + arrColumn, ok := col.(*column.Array) + if ok && strings.Contains(col.CHType(), "Nullable") { + return arrColumn.WriteNull(block.buffers[num].Offset, block.buffers[num].Column, value.Interface()) + } + return col.Write(block.buffers[num].Column, value.Interface()) + } + + switch { + case value.Kind() == reflect.Slice: + if len(block.offsets[num]) < level { + block.offsets[num] = append(block.offsets[num], []int{value.Len()}) + } else { + block.offsets[num][level-1] = append( + block.offsets[num][level-1], + block.offsets[num][level-1][len(block.offsets[num][level-1])-1]+value.Len(), + ) + } + for i := 0; i < value.Len(); i++ { + if err := block.writeArray(col, value.Index(i), num, level+1); err != nil { + return err + } + } + default: + if err := col.Write(block.buffers[num].Column, value.Interface()); err != nil { + return err + } + } + return nil +} + +func (block *Block) AppendRow(args []driver.Value) error { + if len(block.Columns) != len(args) { + return fmt.Errorf("block: expected %d arguments (columns: %s), got %d", len(block.Columns), strings.Join(block.ColumnNames(), ", "), len(args)) + } + block.Reserve() + { + block.NumRows++ + } + for num, c := range block.Columns { + switch column := c.(type) { + case *column.Array: + if args[num] == nil { + return fmt.Errorf("unsupported [nil] value is passed in argument %d, column is not Nullable", num) + } + value := reflect.ValueOf(args[num]) + if value.Kind() != reflect.Slice { + return fmt.Errorf("unsupported Array(T) type [%T]", value.Interface()) + } + if err := block.writeArray(c, newValue(value), num, 1); err != nil { + return err + } + case *column.Nullable: + if err := column.WriteNull(block.buffers[num].Offset, block.buffers[num].Column, args[num]); err != nil { + return err + } + default: + if err := column.Write(block.buffers[num].Column, args[num]); err != nil { + return err + } + } + } + return nil +} + +func (block *Block) Reserve() { + if len(block.buffers) == 0 { + block.buffers = make([]*buffer, len(block.Columns)) + block.offsets = make([]offset, len(block.Columns)) + for i := 0; i < len(block.Columns); i++ { + var ( + offsetBuffer = new(bytes.Buffer) + columnBuffer = new(bytes.Buffer) + ) + block.buffers[i] = &buffer{ + Offset: binary.NewEncoder(offsetBuffer), + Column: binary.NewEncoder(columnBuffer), + offsetBuffer: offsetBuffer, + columnBuffer: columnBuffer, + } + } + } +} + +func (block *Block) Reset() { + block.NumRows = 0 + block.NumColumns = 0 + block.Values = block.Values[:0] + block.Columns = block.Columns[:0] + block.info.reset() + for _, buffer := range block.buffers { + buffer.reset() + } + { + block.offsets = nil + block.buffers = nil + } +} + +func (block *Block) Write(serverInfo *ServerInfo, encoder *binary.Encoder) error { + if serverInfo.Revision > 0 { + if err := block.info.write(encoder); err != nil { + return err + } + } + if err := encoder.Uvarint(block.NumColumns); err != nil { + return err + } + encoder.Uvarint(block.NumRows) + defer func() { + block.NumRows = 0 + for i := range block.offsets { + block.offsets[i] = offset{} + } + }() + for i, column := range block.Columns { + encoder.String(column.Name()) + encoder.String(column.CHType()) + if len(block.buffers) == len(block.Columns) { + for _, offsets := range block.offsets[i] { + for _, offset := range offsets { + if err := encoder.UInt64(uint64(offset)); err != nil { + return err + } + } + } + if _, err := block.buffers[i].WriteTo(encoder); err != nil { + return err + } + } + } + return nil +} + +type blockInfo struct { + num1 uint64 + isOverflows bool + num2 uint64 + bucketNum int32 + num3 uint64 +} + +func (info *blockInfo) reset() { + info.num1 = 0 + info.isOverflows = false + info.num2 = 0 + info.bucketNum = 0 + info.num3 = 0 +} + +func (info *blockInfo) read(decoder *binary.Decoder) error { + var err error + if info.num1, err = decoder.Uvarint(); err != nil { + return err + } + if info.isOverflows, err = decoder.Bool(); err != nil { + return err + } + if info.num2, err = decoder.Uvarint(); err != nil { + return err + } + if info.bucketNum, err = decoder.Int32(); err != nil { + return err + } + if info.num3, err = decoder.Uvarint(); err != nil { + return err + } + return nil +} + +func (info *blockInfo) write(encoder *binary.Encoder) error { + if err := encoder.Uvarint(1); err != nil { + return err + } + if err := encoder.Bool(info.isOverflows); err != nil { + return err + } + if err := encoder.Uvarint(2); err != nil { + return err + } + if info.bucketNum == 0 { + info.bucketNum = -1 + } + if err := encoder.Int32(info.bucketNum); err != nil { + return err + } + if err := encoder.Uvarint(0); err != nil { + return err + } + return nil +} + +type buffer struct { + Offset *binary.Encoder + Column *binary.Encoder + offsetBuffer *bytes.Buffer + columnBuffer *bytes.Buffer +} + +func (buf *buffer) WriteTo(w io.Writer) (int64, error) { + var size int64 + { + ln, err := buf.offsetBuffer.WriteTo(w) + if err != nil { + return size, err + } + size += ln + } + { + ln, err := buf.columnBuffer.WriteTo(w) + if err != nil { + return size, err + } + size += ln + } + return size, nil +} + +func (buf *buffer) reset() { + buf.offsetBuffer.Reset() + buf.columnBuffer.Reset() +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/data/block_write_column.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/block_write_column.go new file mode 100644 index 0000000000..b23ec6fdf4 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/block_write_column.go @@ -0,0 +1,277 @@ +package data + +import ( + "fmt" + "github.com/ClickHouse/clickhouse-go/lib/column" + "net" + "reflect" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +func (block *Block) WriteDate(c int, v time.Time) error { + _, offset := v.Zone() + nday := (v.Unix() + int64(offset)) / 24 / 3600 + return block.buffers[c].Column.UInt16(uint16(nday)) +} + +func (block *Block) WriteDateNullable(c int, v *time.Time) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.UInt16(0) + } + return block.WriteDate(c, *v) +} + +func (block *Block) WriteDateTime(c int, v time.Time) error { + return block.buffers[c].Column.UInt32(uint32(v.Unix())) +} + +func (block *Block) WriteDateTimeNullable(c int, v *time.Time) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.UInt32(0) + } + return block.buffers[c].Column.UInt32(uint32(v.Unix())) +} + +func (block *Block) WriteBool(c int, v bool) error { + if v { + return block.buffers[c].Column.UInt8(1) + } + return block.buffers[c].Column.UInt8(0) +} + +func (block *Block) WriteBoolNullable(c int, v *bool) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil || !(*v) { + return block.buffers[c].Column.UInt8(0) + } + return block.buffers[c].Column.UInt8(1) +} + +func (block *Block) WriteInt8(c int, v int8) error { + return block.buffers[c].Column.Int8(v) +} + +func (block *Block) WriteInt8Nullable(c int, v *int8) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.Int8(0) + } + return block.buffers[c].Column.Int8(*v) +} + +func (block *Block) WriteInt16(c int, v int16) error { + return block.buffers[c].Column.Int16(v) +} + +func (block *Block) WriteInt16Nullable(c int, v *int16) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.Int16(0) + } + return block.buffers[c].Column.Int16(*v) +} + +func (block *Block) WriteInt32(c int, v int32) error { + return block.buffers[c].Column.Int32(v) +} + +func (block *Block) WriteInt32Nullable(c int, v *int32) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.Int32(0) + } + return block.buffers[c].Column.Int32(*v) +} + +func (block *Block) WriteInt64(c int, v int64) error { + return block.buffers[c].Column.Int64(v) +} + +func (block *Block) WriteInt64Nullable(c int, v *int64) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.Int64(0) + } + return block.buffers[c].Column.Int64(*v) +} + +func (block *Block) WriteUInt8(c int, v uint8) error { + return block.buffers[c].Column.UInt8(v) +} + +func (block *Block) WriteUInt8Nullable(c int, v *uint8) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.UInt8(0) + } + return block.buffers[c].Column.UInt8(*v) +} + +func (block *Block) WriteUInt16(c int, v uint16) error { + return block.buffers[c].Column.UInt16(v) +} + +func (block *Block) WriteUInt16Nullable(c int, v *uint16) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.UInt16(0) + } + return block.buffers[c].Column.UInt16(*v) +} + +func (block *Block) WriteUInt32(c int, v uint32) error { + return block.buffers[c].Column.UInt32(v) +} + +func (block *Block) WriteUInt32Nullable(c int, v *uint32) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.UInt32(0) + } + return block.buffers[c].Column.UInt32(*v) +} + +func (block *Block) WriteUInt64(c int, v uint64) error { + return block.buffers[c].Column.UInt64(v) +} + +func (block *Block) WriteUInt64Nullable(c int, v *uint64) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.UInt64(0) + } + return block.buffers[c].Column.UInt64(*v) +} + +func (block *Block) WriteFloat32(c int, v float32) error { + return block.buffers[c].Column.Float32(v) +} + +func (block *Block) WriteFloat32Nullable(c int, v *float32) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.Float32(0) + } + return block.buffers[c].Column.Float32(*v) +} + +func (block *Block) WriteFloat64(c int, v float64) error { + return block.buffers[c].Column.Float64(v) +} + +func (block *Block) WriteFloat64Nullable(c int, v *float64) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.buffers[c].Column.Float64(0) + } + return block.buffers[c].Column.Float64(*v) +} + +func (block *Block) WriteBytes(c int, v []byte) error { + if err := block.buffers[c].Column.Uvarint(uint64(len(v))); err != nil { + return err + } + if _, err := block.buffers[c].Column.Write(v); err != nil { + return err + } + return nil +} + +func (block *Block) WriteBytesNullable(c int, v *[]byte) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.WriteBytes(c, []byte{}) + } + return block.WriteBytes(c, *v) +} + +func (block *Block) WriteString(c int, v string) error { + if err := block.buffers[c].Column.Uvarint(uint64(len(v))); err != nil { + return err + } + if _, err := block.buffers[c].Column.Write(binary.Str2Bytes(v)); err != nil { + return err + } + return nil +} + +func (block *Block) WriteStringNullable(c int, v *string) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.WriteString(c, "") + } + return block.WriteString(c, *v) +} + +func (block *Block) WriteFixedString(c int, v []byte) error { + return block.Columns[c].Write(block.buffers[c].Column, v) +} + +func (block *Block) WriteFixedStringNullable(c int, v *[]byte) error { + writer := block.Columns[c].(*column.Nullable) + return writer.WriteNull(block.buffers[c].Offset, block.buffers[c].Column, v) +} + +func (block *Block) WriteIP(c int, v net.IP) error { + return block.Columns[c].Write(block.buffers[c].Column, v) +} + +func (block *Block) WriteIPNullable(c int, v net.IP) error { + writer := block.Columns[c].(*column.Nullable) + return writer.WriteNull(block.buffers[c].Offset, block.buffers[c].Column, v) +} + +func (block *Block) WriteArray(c int, v interface{}) error { + return block.WriteArrayWithValue(c, newValue(reflect.ValueOf(v))) +} + +func (block *Block) WriteArrayWithValue(c int, value Value) error { + if value.Kind() != reflect.Slice { + return fmt.Errorf("unsupported Array(T) type [%T]", value.Interface()) + } + return block.writeArray(block.Columns[c], value, c, 1) +} + +func (block *Block) WriteArrayNullable(c int, v *interface{}) error { + if err := block.buffers[c].Offset.Bool(v == nil); err != nil { + return err + } + if v == nil { + return block.Columns[c].Write(block.buffers[c].Column, []string{}) + } + return block.WriteArray(c, *v) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/data/client_info.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/client_info.go new file mode 100644 index 0000000000..0bff41981f --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/client_info.go @@ -0,0 +1,29 @@ +package data + +import ( + "fmt" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +const ClientName = "Golang SQLDriver" + +const ( + ClickHouseRevision = 54213 + ClickHouseDBMSVersionMajor = 1 + ClickHouseDBMSVersionMinor = 1 +) + +type ClientInfo struct{} + +func (ClientInfo) Write(encoder *binary.Encoder) error { + encoder.String(ClientName) + encoder.Uvarint(ClickHouseDBMSVersionMajor) + encoder.Uvarint(ClickHouseDBMSVersionMinor) + encoder.Uvarint(ClickHouseRevision) + return nil +} + +func (ClientInfo) String() string { + return fmt.Sprintf("%s %d.%d.%d", ClientName, ClickHouseDBMSVersionMajor, ClickHouseDBMSVersionMinor, ClickHouseRevision) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/data/server_info.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/server_info.go new file mode 100644 index 0000000000..a6c90bed42 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/server_info.go @@ -0,0 +1,47 @@ +package data + +import ( + "fmt" + //"io" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/binary" + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +type ServerInfo struct { + Name string + Revision uint64 + MinorVersion uint64 + MajorVersion uint64 + Timezone *time.Location +} + +func (srv *ServerInfo) Read(decoder *binary.Decoder) (err error) { + if srv.Name, err = decoder.String(); err != nil { + return fmt.Errorf("could not read server name: %v", err) + } + if srv.MajorVersion, err = decoder.Uvarint(); err != nil { + return fmt.Errorf("could not read server major version: %v", err) + } + if srv.MinorVersion, err = decoder.Uvarint(); err != nil { + return fmt.Errorf("could not read server minor version: %v", err) + } + if srv.Revision, err = decoder.Uvarint(); err != nil { + return fmt.Errorf("could not read server revision: %v", err) + } + if srv.Revision >= protocol.DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE { + timezone, err := decoder.String() + if err != nil { + return fmt.Errorf("could not read server timezone: %v", err) + } + if srv.Timezone, err = time.LoadLocation(timezone); err != nil { + return fmt.Errorf("could not load time location: %v", err) + } + } + return nil +} + +func (srv ServerInfo) String() string { + return fmt.Sprintf("%s %d.%d.%d (%s)", srv.Name, srv.MajorVersion, srv.MinorVersion, srv.Revision, srv.Timezone) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/data/value.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/value.go new file mode 100644 index 0000000000..3c7e4ede9b --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/data/value.go @@ -0,0 +1,33 @@ +package data + +import "reflect" + +// Value is a writable value. +type Value interface { + // Kind returns value's Kind. + Kind() reflect.Kind + + // Len returns value's length. + // It panics if value's Kind is not Array, Chan, Map, Slice, or String. + Len() int + + // Index returns value's i'th element. + // It panics if value's Kind is not Array, Slice, or String or i is out of range. + Index(i int) Value + + // Interface returns value's current value as an interface{}. + Interface() interface{} +} + +// value is a wrapper that wraps reflect.Value to comply with Value interface. +type value struct { + reflect.Value +} + +func newValue(v reflect.Value) Value { + return value{Value: v} +} + +func (v value) Index(i int) Value { + return newValue(v.Value.Index(i)) +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/LICENSE b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/LICENSE new file mode 100644 index 0000000000..85cbc1df59 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/LICENSE @@ -0,0 +1,23 @@ +Copyright 2011-2012 Branimir Karadzic. All rights reserved. +Copyright 2013 Damian Gryski. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/doc.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/doc.go new file mode 100644 index 0000000000..091981c8fb --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/doc.go @@ -0,0 +1,7 @@ +// Copyright 2011-2012 Branimir Karadzic. All rights reserved. +// Copyright 2013 Damian Gryski. All rights reserved. + +// @LINK: https://github.com/bkaradzic/go-lz4 +// @NOTE: The code is modified to be high performance and less memory usage + +package lz4 diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/fuzz.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/fuzz.go new file mode 100644 index 0000000000..e4989de9ff --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/fuzz.go @@ -0,0 +1,23 @@ +// +build gofuzz + +package lz4 + +import "encoding/binary" + +func Fuzz(data []byte) int { + + if len(data) < 4 { + return 0 + } + + ln := binary.LittleEndian.Uint32(data) + if ln > (1 << 21) { + return 0 + } + + if _, err := Decode(nil, data); err != nil { + return 0 + } + + return 1 +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/reader.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/reader.go new file mode 100644 index 0000000000..f8d38ea27f --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/reader.go @@ -0,0 +1,179 @@ +/* + * Copyright 2011-2012 Branimir Karadzic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +package lz4 + +import ( + "errors" + "io" +) + +var ( + // ErrCorrupt indicates the input was corrupt + ErrCorrupt = errors.New("corrupt input") +) + +const ( + mlBits = 4 + mlMask = (1 << mlBits) - 1 + runBits = 8 - mlBits + runMask = (1 << runBits) - 1 +) + +type decoder struct { + src []byte + dst []byte + spos uint32 + dpos uint32 + ref uint32 +} + +func (d *decoder) readByte() (uint8, error) { + if int(d.spos) == len(d.src) { + return 0, io.EOF + } + b := d.src[d.spos] + d.spos++ + return b, nil +} + +func (d *decoder) getLen() (uint32, error) { + + length := uint32(0) + ln, err := d.readByte() + if err != nil { + return 0, ErrCorrupt + } + for ln == 255 { + length += 255 + ln, err = d.readByte() + if err != nil { + return 0, ErrCorrupt + } + } + length += uint32(ln) + + return length, nil +} + +func (d *decoder) cp(length, decr uint32) { + + if int(d.ref+length) < int(d.dpos) { + copy(d.dst[d.dpos:], d.dst[d.ref:d.ref+length]) + } else { + for ii := uint32(0); ii < length; ii++ { + d.dst[d.dpos+ii] = d.dst[d.ref+ii] + } + } + d.dpos += length + d.ref += length - decr +} + +func (d *decoder) finish(err error) error { + if err == io.EOF { + return nil + } + + return err +} + +// Decode returns the decoded form of src. The returned slice may be a +// subslice of dst if it was large enough to hold the entire decoded block. +func Decode(dst, src []byte) (int, error) { + d := decoder{src: src, dst: dst, spos: 0} + + decr := []uint32{0, 3, 2, 3} + + for { + code, err := d.readByte() + if err != nil { + return len(d.dst), d.finish(err) + } + + length := uint32(code >> mlBits) + if length == runMask { + ln, err := d.getLen() + if err != nil { + return 0, ErrCorrupt + } + length += ln + } + + if int(d.spos+length) > len(d.src) || int(d.dpos+length) > len(d.dst) { + return 0, ErrCorrupt + } + + for ii := uint32(0); ii < length; ii++ { + d.dst[d.dpos+ii] = d.src[d.spos+ii] + } + + d.spos += length + d.dpos += length + + if int(d.spos) == len(d.src) { + return len(d.dst), nil + } + + if int(d.spos+2) >= len(d.src) { + return 0, ErrCorrupt + } + + back := uint32(d.src[d.spos]) | uint32(d.src[d.spos+1])<<8 + + if back > d.dpos { + return 0, ErrCorrupt + } + + d.spos += 2 + d.ref = d.dpos - back + + length = uint32(code & mlMask) + if length == mlMask { + ln, err := d.getLen() + if err != nil { + return 0, ErrCorrupt + } + length += ln + } + + literal := d.dpos - d.ref + + if literal < 4 { + if int(d.dpos+4) > len(d.dst) { + return 0, ErrCorrupt + } + + d.cp(4, decr[literal]) + } else { + length += 4 + } + + if int(d.dpos+length) > len(d.dst) { + return 0, ErrCorrupt + } + + d.cp(length, 0) + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/writer.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/writer.go new file mode 100644 index 0000000000..969311beaf --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/lz4/writer.go @@ -0,0 +1,203 @@ +/* + * Copyright 2011-2012 Branimir Karadzic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +package lz4 + +import ( + "errors" + "sync" +) + +const ( + minMatch = 4 + hashLog = 16 + hashTableSize = 1 << hashLog + hashShift = (minMatch * 8) - hashLog + incompressible uint32 = 128 + uninitHash = 0x88888888 + + mfLimit = 8 + minMatch // The last match cannot start within the last 12 bytes. + // MaxInputSize is the largest buffer than can be compressed in a single block + MaxInputSize = 0x7E000000 +) + +var ( + // ErrTooLarge indicates the input buffer was too large + ErrTooLarge = errors.New("input too large") + ErrEncodeTooSmall = errors.New("encode buffer too small") + + hashPool = sync.Pool{ + New: func() interface{} { + return make([]uint32, hashTableSize) + }, + } +) + +type encoder struct { + src []byte + dst []byte + hashTable []uint32 + pos uint32 + anchor uint32 + dpos uint32 +} + +// CompressBound returns the maximum length of a lz4 block +func CompressBound(isize int) int { + if isize > MaxInputSize { + return 0 + } + return isize + ((isize) / 255) + 16 +} + +func (e *encoder) writeLiterals(length, mlLen, pos uint32) { + + ln := length + + var code byte + if ln > runMask-1 { + code = runMask + } else { + code = byte(ln) + } + + if mlLen > mlMask-1 { + e.dst[e.dpos] = (code << mlBits) + byte(mlMask) + } else { + e.dst[e.dpos] = (code << mlBits) + byte(mlLen) + } + e.dpos++ + + if code == runMask { + ln -= runMask + for ; ln > 254; ln -= 255 { + e.dst[e.dpos] = 255 + e.dpos++ + } + + e.dst[e.dpos] = byte(ln) + e.dpos++ + } + + for ii := uint32(0); ii < length; ii++ { + e.dst[e.dpos+ii] = e.src[pos+ii] + } + + e.dpos += length +} + +// Encode returns the encoded form of src. The returned array may be a +// sub-slice of dst if it was large enough to hold the entire output. +func Encode(dst, src []byte) (compressedSize int, error error) { + if len(src) >= MaxInputSize { + return 0, ErrTooLarge + } + + if n := CompressBound(len(src)); len(dst) < n { + return 0, ErrEncodeTooSmall + } + + hashTable := hashPool.Get().([]uint32) + for i := range hashTable { + hashTable[i] = 0 + } + e := encoder{src: src, dst: dst, hashTable: hashTable} + defer func() { + hashPool.Put(hashTable) + }() + // binary.LittleEndian.PutUint32(dst, uint32(len(src))) + // e.dpos = 0 + + var ( + step uint32 = 1 + limit = incompressible + ) + + for { + if int(e.pos)+12 >= len(e.src) { + e.writeLiterals(uint32(len(e.src))-e.anchor, 0, e.anchor) + return int(e.dpos), nil + } + + sequence := uint32(e.src[e.pos+3])<<24 | uint32(e.src[e.pos+2])<<16 | uint32(e.src[e.pos+1])<<8 | uint32(e.src[e.pos+0]) + + hash := (sequence * 2654435761) >> hashShift + ref := e.hashTable[hash] + uninitHash + e.hashTable[hash] = e.pos - uninitHash + + if ((e.pos-ref)>>16) != 0 || uint32(e.src[ref+3])<<24|uint32(e.src[ref+2])<<16|uint32(e.src[ref+1])<<8|uint32(e.src[ref+0]) != sequence { + if e.pos-e.anchor > limit { + limit <<= 1 + step += 1 + (step >> 2) + } + e.pos += step + continue + } + + if step > 1 { + e.hashTable[hash] = ref - uninitHash + e.pos -= step - 1 + step = 1 + continue + } + limit = incompressible + + ln := e.pos - e.anchor + back := e.pos - ref + + anchor := e.anchor + + e.pos += minMatch + ref += minMatch + e.anchor = e.pos + + for int(e.pos) < len(e.src)-5 && e.src[e.pos] == e.src[ref] { + e.pos++ + ref++ + } + + mlLen := e.pos - e.anchor + + e.writeLiterals(ln, mlLen, anchor) + e.dst[e.dpos] = uint8(back) + e.dst[e.dpos+1] = uint8(back >> 8) + e.dpos += 2 + + if mlLen > mlMask-1 { + mlLen -= mlMask + for mlLen > 254 { + mlLen -= 255 + + e.dst[e.dpos] = 255 + e.dpos++ + } + + e.dst[e.dpos] = byte(mlLen) + e.dpos++ + } + + e.anchor = e.pos + } +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/protocol/README.md b/vendor/github.com/ClickHouse/clickhouse-go/lib/protocol/README.md new file mode 100644 index 0000000000..84fdd48c6e --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/protocol/README.md @@ -0,0 +1,4 @@ +# ClickHouse Native protocol + +# Handshake + diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/protocol/protocol.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/protocol/protocol.go new file mode 100644 index 0000000000..ba5fd7c7ba --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/protocol/protocol.go @@ -0,0 +1,35 @@ +package protocol + +const ( + DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE = 54058 + DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO = 54060 +) + +const ( + ClientHello = 0 + ClientQuery = 1 + ClientData = 2 + ClientCancel = 3 + ClientPing = 4 +) + +const ( + CompressEnable uint64 = 1 + CompressDisable uint64 = 0 +) + +const ( + StateComplete = 2 +) + +const ( + ServerHello = 0 + ServerData = 1 + ServerException = 2 + ServerProgress = 3 + ServerPong = 4 + ServerEndOfStream = 5 + ServerProfileInfo = 6 + ServerTotals = 7 + ServerExtremes = 8 +) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/types/date.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/types/date.go new file mode 100644 index 0000000000..a7d0143b63 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/types/date.go @@ -0,0 +1,48 @@ +// Timezoneless date/datetime types + +package types + +import ( + "database/sql/driver" + "time" +) + +// Truncate timezone +// +// clickhouse.Date(time.Date(2017, 1, 1, 0, 0, 0, 0, time.Local)) -> time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC) +type Date time.Time + +func (date Date) Value() (driver.Value, error) { + return date.convert(), nil +} + +func (date Date) convert() time.Time { + return time.Date(time.Time(date).Year(), time.Time(date).Month(), time.Time(date).Day(), 0, 0, 0, 0, time.UTC) +} + +// Truncate timezone +// +// clickhouse.DateTime(time.Date(2017, 1, 1, 0, 0, 0, 0, time.Local)) -> time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC) +type DateTime time.Time + +func (datetime DateTime) Value() (driver.Value, error) { + return datetime.convert(), nil +} + +func (datetime DateTime) convert() time.Time { + return time.Date( + time.Time(datetime).Year(), + time.Time(datetime).Month(), + time.Time(datetime).Day(), + time.Time(datetime).Hour(), + time.Time(datetime).Minute(), + time.Time(datetime).Second(), + 1, + time.UTC, + ) +} + +var ( + _ driver.Valuer = Date{} + _ driver.Valuer = DateTime{} +) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/lib/types/uuid.go b/vendor/github.com/ClickHouse/clickhouse-go/lib/types/uuid.go new file mode 100644 index 0000000000..dc270a85f8 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/lib/types/uuid.go @@ -0,0 +1,99 @@ +package types + +import ( + "database/sql/driver" + "encoding/hex" + "errors" + "fmt" +) + +var InvalidUUIDFormatError = errors.New("invalid UUID format") + +// this type will be deprecated because the ClickHouse server (>=1.1.54276) has a built-in type UUID +type UUID string + +func (str UUID) Value() (driver.Value, error) { + return uuid2bytes(string(str)) +} + +func (str UUID) MarshalBinary() ([]byte, error) { + return uuid2bytes(string(str)) +} + +func (str *UUID) Scan(v interface{}) error { + var src []byte + switch v := v.(type) { + case string: + src = []byte(v) + case []byte: + src = v + } + + if len(src) != 16 { + return fmt.Errorf("invalid UUID length: %d", len(src)) + } + + var uuid [36]byte + { + hex.Encode(uuid[:], src[:4]) + uuid[8] = '-' + hex.Encode(uuid[9:13], src[4:6]) + uuid[13] = '-' + hex.Encode(uuid[14:18], src[6:8]) + uuid[18] = '-' + hex.Encode(uuid[19:23], src[8:10]) + uuid[23] = '-' + hex.Encode(uuid[24:], src[10:]) + } + *str = UUID(uuid[:]) + return nil +} + +func uuid2bytes(str string) ([]byte, error) { + var uuid [16]byte + if str[8] != '-' || str[13] != '-' || str[18] != '-' || str[23] != '-' { + return nil, InvalidUUIDFormatError + } + for i, x := range [16]int{ + 0, 2, 4, 6, + 9, 11, 14, 16, + 19, 21, 24, 26, + 28, 30, 32, 34, + } { + if v, ok := xtob(str[x], str[x+1]); !ok { + return nil, InvalidUUIDFormatError + } else { + uuid[i] = v + } + } + return uuid[:], nil +} + +// xvalues returns the value of a byte as a hexadecimal digit or 255. +var xvalues = [256]byte{ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, + 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, +} + +// xtob converts hex characters x1 and x2 into a byte. +func xtob(x1, x2 byte) (byte, bool) { + b1 := xvalues[x1] + b2 := xvalues[x2] + return (b1 << 4) | b2, b1 != 255 && b2 != 255 +} + +var _ driver.Valuer = UUID("") diff --git a/vendor/github.com/ClickHouse/clickhouse-go/query_settings.go b/vendor/github.com/ClickHouse/clickhouse-go/query_settings.go new file mode 100644 index 0000000000..506728cc47 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/query_settings.go @@ -0,0 +1,286 @@ +package clickhouse + +import ( + "fmt" + "net/url" + "strconv" + + "github.com/ClickHouse/clickhouse-go/lib/binary" +) + +type querySettingType int + +// all possible query setting's data type +const ( + uintQS querySettingType = iota + 1 + intQS + boolQS + timeQS +) + +// description of single query setting +type querySettingInfo struct { + name string + qsType querySettingType +} + +// all possible query settings +var querySettingList = []querySettingInfo{ + {"min_compress_block_size", uintQS}, + {"max_compress_block_size", uintQS}, + {"max_block_size", uintQS}, + {"max_insert_block_size", uintQS}, + {"min_insert_block_size_rows", uintQS}, + {"min_insert_block_size_bytes", uintQS}, + {"max_read_buffer_size", uintQS}, + {"max_distributed_connections", uintQS}, + {"max_query_size", uintQS}, + {"interactive_delay", uintQS}, + {"poll_interval", uintQS}, + {"distributed_connections_pool_size", uintQS}, + {"connections_with_failover_max_tries", uintQS}, + {"background_pool_size", uintQS}, + {"background_schedule_pool_size", uintQS}, + {"replication_alter_partitions_sync", uintQS}, + {"replication_alter_columns_timeout", uintQS}, + {"min_count_to_compile", uintQS}, + {"min_count_to_compile_expression", uintQS}, + {"group_by_two_level_threshold", uintQS}, + {"group_by_two_level_threshold_bytes", uintQS}, + {"aggregation_memory_efficient_merge_threads", uintQS}, + {"max_parallel_replicas", uintQS}, + {"parallel_replicas_count", uintQS}, + {"parallel_replica_offset", uintQS}, + {"merge_tree_min_rows_for_concurrent_read", uintQS}, + {"merge_tree_min_bytes_for_concurrent_read", uintQS}, + {"merge_tree_min_rows_for_seek", uintQS}, + {"merge_tree_min_bytes_for_seek", uintQS}, + {"merge_tree_coarse_index_granularity", uintQS}, + {"merge_tree_max_rows_to_use_cache", uintQS}, + {"merge_tree_max_bytes_to_use_cache", uintQS}, + {"mysql_max_rows_to_insert", uintQS}, + {"optimize_min_equality_disjunction_chain_length", uintQS}, + {"min_bytes_to_use_direct_io", uintQS}, + {"mark_cache_min_lifetime", uintQS}, + {"priority", uintQS}, + {"log_queries_cut_to_length", uintQS}, + {"max_concurrent_queries_for_user", uintQS}, + {"insert_quorum", uintQS}, + {"select_sequential_consistency", uintQS}, + {"table_function_remote_max_addresses", uintQS}, + {"read_backoff_max_throughput", uintQS}, + {"read_backoff_min_events", uintQS}, + {"output_format_pretty_max_rows", uintQS}, + {"output_format_pretty_max_column_pad_width", uintQS}, + {"output_format_parquet_row_group_size", uintQS}, + {"http_headers_progress_interval_ms", uintQS}, + {"input_format_allow_errors_num", uintQS}, + {"preferred_block_size_bytes", uintQS}, + {"max_replica_delay_for_distributed_queries", uintQS}, + {"preferred_max_column_in_block_size_bytes", uintQS}, + {"insert_distributed_timeout", uintQS}, + {"odbc_max_field_size", uintQS}, + {"max_rows_to_read", uintQS}, + {"max_bytes_to_read", uintQS}, + {"max_rows_to_group_by", uintQS}, + {"max_bytes_before_external_group_by", uintQS}, + {"max_rows_to_sort", uintQS}, + {"max_bytes_to_sort", uintQS}, + {"max_bytes_before_external_sort", uintQS}, + {"max_bytes_before_remerge_sort", uintQS}, + {"max_result_rows", uintQS}, + {"max_result_bytes", uintQS}, + {"min_execution_speed", uintQS}, + {"max_execution_speed", uintQS}, + {"min_execution_speed_bytes", uintQS}, + {"max_execution_speed_bytes", uintQS}, + {"max_columns_to_read", uintQS}, + {"max_temporary_columns", uintQS}, + {"max_temporary_non_const_columns", uintQS}, + {"max_subquery_depth", uintQS}, + {"max_pipeline_depth", uintQS}, + {"max_ast_depth", uintQS}, + {"max_ast_elements", uintQS}, + {"max_expanded_ast_elements", uintQS}, + {"readonly", uintQS}, + {"max_rows_in_set", uintQS}, + {"max_bytes_in_set", uintQS}, + {"max_rows_in_join", uintQS}, + {"max_bytes_in_join", uintQS}, + {"max_rows_to_transfer", uintQS}, + {"max_bytes_to_transfer", uintQS}, + {"max_rows_in_distinct", uintQS}, + {"max_bytes_in_distinct", uintQS}, + {"max_memory_usage", uintQS}, + {"max_memory_usage_for_user", uintQS}, + {"max_memory_usage_for_all_queries", uintQS}, + {"max_network_bandwidth", uintQS}, + {"max_network_bytes", uintQS}, + {"max_network_bandwidth_for_user", uintQS}, + {"max_network_bandwidth_for_all_users", uintQS}, + {"low_cardinality_max_dictionary_size", uintQS}, + {"max_fetch_partition_retries_count", uintQS}, + {"http_max_multipart_form_data_size", uintQS}, + {"max_partitions_per_insert_block", uintQS}, + {"max_threads", uintQS}, + {"optimize_skip_unused_shards_nesting", uintQS}, + {"force_optimize_skip_unused_shards", uintQS}, + {"force_optimize_skip_unused_shards_nesting", uintQS}, + + {"network_zstd_compression_level", intQS}, + {"http_zlib_compression_level", intQS}, + {"distributed_ddl_task_timeout", intQS}, + + {"extremes", boolQS}, + {"use_uncompressed_cache", boolQS}, + {"replace_running_query", boolQS}, + {"distributed_directory_monitor_batch_inserts", boolQS}, + {"optimize_move_to_prewhere", boolQS}, + {"compile", boolQS}, + {"allow_suspicious_low_cardinality_types", boolQS}, + {"compile_expressions", boolQS}, + {"distributed_aggregation_memory_efficient", boolQS}, + {"skip_unavailable_shards", boolQS}, + {"distributed_group_by_no_merge", boolQS}, + {"optimize_skip_unused_shards", boolQS}, + {"merge_tree_uniform_read_distribution", boolQS}, + {"force_index_by_date", boolQS}, + {"force_primary_key", boolQS}, + {"log_queries", boolQS}, + {"insert_deduplicate", boolQS}, + {"enable_http_compression", boolQS}, + {"http_native_compression_disable_checksumming_on_decompress", boolQS}, + {"output_format_write_statistics", boolQS}, + {"add_http_cors_header", boolQS}, + {"input_format_skip_unknown_fields", boolQS}, + {"input_format_with_names_use_header", boolQS}, + {"input_format_import_nested_json", boolQS}, + {"input_format_defaults_for_omitted_fields", boolQS}, + {"input_format_values_interpret_expressions", boolQS}, + {"output_format_json_quote_64bit_integers", boolQS}, + {"output_format_json_quote_denormals", boolQS}, + {"output_format_json_escape_forward_slashes", boolQS}, + {"output_format_pretty_color", boolQS}, + {"use_client_time_zone", boolQS}, + {"send_progress_in_http_headers", boolQS}, + {"fsync_metadata", boolQS}, + {"join_use_nulls", boolQS}, + {"fallback_to_stale_replicas_for_distributed_queries", boolQS}, + {"insert_distributed_sync", boolQS}, + {"insert_allow_materialized_columns", boolQS}, + {"optimize_throw_if_noop", boolQS}, + {"use_index_for_in_with_subqueries", boolQS}, + {"empty_result_for_aggregation_by_empty_set", boolQS}, + {"allow_distributed_ddl", boolQS}, + {"join_any_take_last_row", boolQS}, + {"format_csv_allow_single_quotes", boolQS}, + {"format_csv_allow_double_quotes", boolQS}, + {"log_profile_events", boolQS}, + {"log_query_settings", boolQS}, + {"log_query_threads", boolQS}, + {"enable_optimize_predicate_expression", boolQS}, + {"low_cardinality_use_single_dictionary_for_part", boolQS}, + {"decimal_check_overflow", boolQS}, + {"prefer_localhost_replica", boolQS}, + //{"asterisk_left_columns_only", boolQS}, + {"calculate_text_stack_trace", boolQS}, + {"allow_ddl", boolQS}, + {"parallel_view_processing", boolQS}, + {"enable_debug_queries", boolQS}, + {"enable_unaligned_array_join", boolQS}, + {"low_cardinality_allow_in_native_format", boolQS}, + {"allow_experimental_multiple_joins_emulation", boolQS}, + {"allow_experimental_cross_to_join_conversion", boolQS}, + {"cancel_http_readonly_queries_on_client_close", boolQS}, + {"external_table_functions_use_nulls", boolQS}, + {"allow_experimental_data_skipping_indices", boolQS}, + {"allow_hyperscan", boolQS}, + {"allow_simdjson", boolQS}, + + {"connect_timeout", timeQS}, + {"connect_timeout_with_failover_ms", timeQS}, + {"receive_timeout", timeQS}, + {"send_timeout", timeQS}, + {"tcp_keep_alive_timeout", timeQS}, + {"queue_max_wait_ms", timeQS}, + {"distributed_directory_monitor_sleep_time_ms", timeQS}, + {"insert_quorum_timeout", timeQS}, + {"read_backoff_min_latency_ms", timeQS}, + {"read_backoff_min_interval_between_events_ms", timeQS}, + {"stream_flush_interval_ms", timeQS}, + {"stream_poll_timeout_ms", timeQS}, + {"http_connection_timeout", timeQS}, + {"http_send_timeout", timeQS}, + {"http_receive_timeout", timeQS}, + {"max_execution_time", timeQS}, + {"timeout_before_checking_execution_speed", timeQS}, +} + +type querySettingValueEncoder func(enc *binary.Encoder) error + +type querySettings struct { + settings map[string]querySettingValueEncoder + settingsStr string // used for debug output +} + +func makeQuerySettings(query url.Values) (*querySettings, error) { + qs := &querySettings{ + settings: make(map[string]querySettingValueEncoder), + settingsStr: "", + } + + for _, info := range querySettingList { + valueStr := query.Get(info.name) + if valueStr == "" { + continue + } + + switch info.qsType { + case uintQS, intQS, timeQS: + value, err := strconv.ParseUint(valueStr, 10, 64) + if err != nil { + return nil, err + } + qs.settings[info.name] = func(enc *binary.Encoder) error { return enc.Uvarint(value) } + + case boolQS: + valueBool, err := strconv.ParseBool(valueStr) + if err != nil { + return nil, err + } + value := uint64(0) + if valueBool { + value = 1 + } + qs.settings[info.name] = func(enc *binary.Encoder) error { return enc.Uvarint(value) } + + default: + err := fmt.Errorf("query setting %s has unsupported data type", info.name) + return nil, err + } + + if qs.settingsStr != "" { + qs.settingsStr += "&" + } + qs.settingsStr += info.name + "=" + valueStr + } + + return qs, nil +} + +func (qs *querySettings) IsEmpty() bool { + return len(qs.settings) == 0 +} + +func (qs *querySettings) Serialize(enc *binary.Encoder) error { + for name, fn := range qs.settings { + if err := enc.String(name); err != nil { + return err + } + if err := fn(enc); err != nil { + return err + } + } + + return nil +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/result.go b/vendor/github.com/ClickHouse/clickhouse-go/result.go new file mode 100644 index 0000000000..fc08cf4dc4 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/result.go @@ -0,0 +1,8 @@ +package clickhouse + +import "errors" + +type result struct{} + +func (*result) LastInsertId() (int64, error) { return 0, errors.New("LastInsertId is not supported") } +func (*result) RowsAffected() (int64, error) { return 0, errors.New("RowsAffected is not supported") } diff --git a/vendor/github.com/ClickHouse/clickhouse-go/rows.go b/vendor/github.com/ClickHouse/clickhouse-go/rows.go new file mode 100644 index 0000000000..30e844f651 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/rows.go @@ -0,0 +1,182 @@ +package clickhouse + +import ( + "database/sql/driver" + "fmt" + "io" + "reflect" + "sync" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/column" + "github.com/ClickHouse/clickhouse-go/lib/data" + "github.com/ClickHouse/clickhouse-go/lib/protocol" +) + +type rows struct { + ch *clickhouse + err error + mutex sync.RWMutex + finish func() + offset int + block *data.Block + totals *data.Block + extremes *data.Block + stream chan *data.Block + columns []string + blockColumns []column.Column +} + +func (rows *rows) Columns() []string { + return rows.columns +} + +func (rows *rows) ColumnTypeScanType(idx int) reflect.Type { + return rows.blockColumns[idx].ScanType() +} + +func (rows *rows) ColumnTypeDatabaseTypeName(idx int) string { + return rows.blockColumns[idx].CHType() +} + +func (rows *rows) Next(dest []driver.Value) error { + if rows.block == nil || int(rows.block.NumRows) <= rows.offset { + switch block, ok := <-rows.stream; true { + case !ok: + if err := rows.error(); err != nil { + return err + } + return io.EOF + default: + rows.block = block + rows.offset = 0 + } + } + for i := range dest { + dest[i] = rows.block.Values[i][rows.offset] + } + rows.offset++ + return nil +} + +func (rows *rows) HasNextResultSet() bool { + return rows.totals != nil || rows.extremes != nil +} + +func (rows *rows) NextResultSet() error { + switch { + case rows.totals != nil: + rows.block = rows.totals + rows.offset = 0 + rows.totals = nil + case rows.extremes != nil: + rows.block = rows.extremes + rows.offset = 0 + rows.extremes = nil + default: + return io.EOF + } + return nil +} + +func (rows *rows) receiveData() error { + defer close(rows.stream) + var ( + err error + packet uint64 + progress *progress + profileInfo *profileInfo + ) + for { + if packet, err = rows.ch.decoder.Uvarint(); err != nil { + return rows.setError(err) + } + switch packet { + case protocol.ServerException: + rows.ch.logf("[rows] <- exception") + return rows.setError(rows.ch.exception()) + case protocol.ServerProgress: + if progress, err = rows.ch.progress(); err != nil { + return rows.setError(err) + } + rows.ch.logf("[rows] <- progress: rows=%d, bytes=%d, total rows=%d", + progress.rows, + progress.bytes, + progress.totalRows, + ) + case protocol.ServerProfileInfo: + if profileInfo, err = rows.ch.profileInfo(); err != nil { + return rows.setError(err) + } + rows.ch.logf("[rows] <- profiling: rows=%d, bytes=%d, blocks=%d", profileInfo.rows, profileInfo.bytes, profileInfo.blocks) + case protocol.ServerData, protocol.ServerTotals, protocol.ServerExtremes: + var ( + block *data.Block + begin = time.Now() + ) + if block, err = rows.ch.readBlock(); err != nil { + return rows.setError(err) + } + rows.ch.logf("[rows] <- data: packet=%d, columns=%d, rows=%d, elapsed=%s", packet, block.NumColumns, block.NumRows, time.Since(begin)) + if block.NumRows == 0 { + continue + } + switch packet { + case protocol.ServerData: + rows.stream <- block + case protocol.ServerTotals: + rows.totals = block + case protocol.ServerExtremes: + rows.extremes = block + } + case protocol.ServerEndOfStream: + rows.ch.logf("[rows] <- end of stream") + return nil + default: + rows.ch.conn.Close() + rows.ch.logf("[rows] unexpected packet [%d]", packet) + return rows.setError(fmt.Errorf("[rows] unexpected packet [%d] from server", packet)) + } + } +} + +func (rows *rows) Close() error { + rows.ch.logf("[rows] close") + rows.columns = nil + for range rows.stream { + } + rows.finish() + return nil +} + +func (rows *rows) error() error { + rows.mutex.RLock() + defer rows.mutex.RUnlock() + return rows.err +} + +func (rows *rows) setError(err error) error { + rows.mutex.Lock() + rows.err = err + rows.mutex.Unlock() + return err +} + +func (rows *rows) ColumnTypeNullable(idx int) (nullable, ok bool) { + _, ok = rows.blockColumns[idx].(*column.Nullable) + return ok, true +} + +func (rows *rows) ColumnTypePrecisionScale(idx int) (precision, scale int64, ok bool) { + decimalVal, ok := rows.blockColumns[idx].(*column.Decimal) + if !ok { + if nullable, nullOk := rows.blockColumns[idx].(*column.Nullable); nullOk { + decimalVal, ok = nullable.GetColumn().(*column.Decimal) + } + } + if ok { + return int64(decimalVal.GetPrecision()), int64(decimalVal.GetScale()), ok + + } + return 0, 0, false +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/stmt.go b/vendor/github.com/ClickHouse/clickhouse-go/stmt.go new file mode 100644 index 0000000000..168a0dfe36 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/stmt.go @@ -0,0 +1,215 @@ +package clickhouse + +import ( + "bytes" + "context" + "database/sql/driver" + "unicode" + + "github.com/ClickHouse/clickhouse-go/lib/data" +) + +type stmt struct { + ch *clickhouse + query string + counter int + numInput int + isInsert bool +} + +var emptyResult = &result{} + +type key string + +var queryIDKey key + +//Put query ID into context and use it in ExecContext or QueryContext +func WithQueryID(ctx context.Context, queryID string) context.Context { + return context.WithValue(ctx, queryIDKey, queryID) +} + +func (stmt *stmt) NumInput() int { + switch { + case stmt.ch.block != nil: + return len(stmt.ch.block.Columns) + case stmt.numInput < 0: + return 0 + } + return stmt.numInput +} + +func (stmt *stmt) Exec(args []driver.Value) (driver.Result, error) { + return stmt.execContext(context.Background(), args) +} + +func (stmt *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { + dargs := make([]driver.Value, len(args)) + for i, nv := range args { + dargs[i] = nv.Value + } + return stmt.execContext(ctx, dargs) +} + +func (stmt *stmt) execContext(ctx context.Context, args []driver.Value) (driver.Result, error) { + if stmt.isInsert { + stmt.counter++ + if err := stmt.ch.block.AppendRow(args); err != nil { + return nil, err + } + if (stmt.counter % stmt.ch.blockSize) == 0 { + stmt.ch.logf("[exec] flush block") + if err := stmt.ch.writeBlock(stmt.ch.block, ""); err != nil { + return nil, err + } + if err := stmt.ch.encoder.Flush(); err != nil { + return nil, err + } + } + return emptyResult, nil + } + query, externalTables := stmt.bind(convertOldArgs(args)) + if err := stmt.ch.sendQuery(ctx, query, externalTables); err != nil { + return nil, err + } + if err := stmt.ch.process(); err != nil { + return nil, err + } + return emptyResult, nil +} + +func (stmt *stmt) Query(args []driver.Value) (driver.Rows, error) { + return stmt.queryContext(context.Background(), convertOldArgs(args)) +} + +func (stmt *stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { + return stmt.queryContext(ctx, args) +} + +func (stmt *stmt) queryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) { + finish := stmt.ch.watchCancel(ctx) + query, externalTables := stmt.bind(args) + if err := stmt.ch.sendQuery(ctx, query, externalTables); err != nil { + finish() + return nil, err + } + meta, err := stmt.ch.readMeta() + if err != nil { + finish() + return nil, err + } + rows := rows{ + ch: stmt.ch, + finish: finish, + stream: make(chan *data.Block, 50), + columns: meta.ColumnNames(), + blockColumns: meta.Columns, + } + go rows.receiveData() + return &rows, nil +} + +func (stmt *stmt) Close() error { + stmt.ch.logf("[stmt] close") + return nil +} + +func (stmt *stmt) bind(args []driver.NamedValue) (string, []ExternalTable) { + var ( + buf bytes.Buffer + index int + keyword bool + inBetween bool + like = newMatcher("like") + limit = newMatcher("limit") + offset = newMatcher("offset") + between = newMatcher("between") + and = newMatcher("and") + in = newMatcher("in") + from = newMatcher("from") + join = newMatcher("join") + subSelect = newMatcher("select") + externalTables = make([]ExternalTable, 0) + ) + switch { + case stmt.NumInput() != 0: + reader := bytes.NewReader([]byte(stmt.query)) + for { + if char, _, err := reader.ReadRune(); err == nil { + switch char { + case '@': + if param := paramParser(reader); len(param) != 0 { + for _, v := range args { + if len(v.Name) != 0 && v.Name == param { + switch v := v.Value.(type) { + case ExternalTable: + buf.WriteString(v.Name) + externalTables = append(externalTables, v) + default: + buf.WriteString(quote(v)) + } + } + } + } + case '?': + if keyword && index < len(args) && len(args[index].Name) == 0 { + switch v := args[index].Value.(type) { + case ExternalTable: + buf.WriteString(v.Name) + externalTables = append(externalTables, v) + default: + buf.WriteString(quote(v)) + } + index++ + } else { + buf.WriteRune(char) + } + default: + switch { + case + char == '=', + char == '<', + char == '>', + char == '(', + char == ',', + char == '+', + char == '-', + char == '*', + char == '/', + char == '[': + keyword = true + default: + if limit.matchRune(char) || offset.matchRune(char) || like.matchRune(char) || + in.matchRune(char) || from.matchRune(char) || join.matchRune(char) || subSelect.matchRune(char) { + keyword = true + } else if between.matchRune(char) { + keyword = true + inBetween = true + } else if inBetween && and.matchRune(char) { + keyword = true + inBetween = false + } else { + keyword = keyword && unicode.IsSpace(char) + } + } + buf.WriteRune(char) + } + } else { + break + } + } + default: + buf.WriteString(stmt.query) + } + return buf.String(), externalTables +} + +func convertOldArgs(args []driver.Value) []driver.NamedValue { + dargs := make([]driver.NamedValue, len(args)) + for i, v := range args { + dargs[i] = driver.NamedValue{ + Ordinal: i + 1, + Value: v, + } + } + return dargs +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/tls_config.go b/vendor/github.com/ClickHouse/clickhouse-go/tls_config.go new file mode 100644 index 0000000000..d85cd341fa --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/tls_config.go @@ -0,0 +1,44 @@ +package clickhouse + +import ( + "crypto/tls" + "sync" +) + +// Based on the original implementation in the project go-sql-driver/mysql: +// https://github.com/go-sql-driver/mysql/blob/master/utils.go + +var ( + tlsConfigLock sync.RWMutex + tlsConfigRegistry map[string]*tls.Config +) + +// RegisterTLSConfig registers a custom tls.Config to be used with sql.Open. +func RegisterTLSConfig(key string, config *tls.Config) error { + tlsConfigLock.Lock() + if tlsConfigRegistry == nil { + tlsConfigRegistry = make(map[string]*tls.Config) + } + + tlsConfigRegistry[key] = config + tlsConfigLock.Unlock() + return nil +} + +// DeregisterTLSConfig removes the tls.Config associated with key. +func DeregisterTLSConfig(key string) { + tlsConfigLock.Lock() + if tlsConfigRegistry != nil { + delete(tlsConfigRegistry, key) + } + tlsConfigLock.Unlock() +} + +func getTLSConfigClone(key string) (config *tls.Config) { + tlsConfigLock.RLock() + if v, ok := tlsConfigRegistry[key]; ok { + config = v.Clone() + } + tlsConfigLock.RUnlock() + return +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/LICENSE b/vendor/github.com/ClickHouse/clickhouse-go/v2/LICENSE deleted file mode 100644 index 7a4a3ea242..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/Makefile b/vendor/github.com/ClickHouse/clickhouse-go/v2/Makefile deleted file mode 100644 index e925c29af3..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -up: - @docker compose up -d -down: - @docker compose down - -cli: - docker run -it --rm --net clickhouse-go_clickhouse --link clickhouse:clickhouse-server yandex/clickhouse-client --host clickhouse-server - -test: - @go install -race -v - @go test -race -timeout 30s -count=1 -v . - @go test -race -timeout 30s -count=1 -v ./tests/... - -lint: - golangci-lint run || : - gocritic check -disable=singleCaseSwitch ./... || : - -contributors: - @git log --pretty="%an <%ae>%n%cn <%ce>" | sort -u -t '<' -k 2,2 | LC_ALL=C sort | \ - grep -v "users.noreply.github.com\|GitHub " \ - > contributors/list - -staticcheck: - staticcheck ./... - -codegen: contributors - @cd lib/column && go run codegen/main.go - @go-licenser -licensor "ClickHouse, Inc." - -.PHONY: contributors \ No newline at end of file diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/README.md b/vendor/github.com/ClickHouse/clickhouse-go/v2/README.md deleted file mode 100644 index 1cbcd10f4c..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/README.md +++ /dev/null @@ -1,162 +0,0 @@ -# ClickHouse [![run-tests](https://github.com/ClickHouse/clickhouse-go/actions/workflows/run-tests.yml/badge.svg?branch=v2)](https://github.com/ClickHouse/clickhouse-go/actions/workflows/run-tests.yml) [![Go Reference](https://pkg.go.dev/badge/github.com/ClickHouse/clickhouse-go/v2.svg)](https://pkg.go.dev/github.com/ClickHouse/clickhouse-go/v2) - -Golang SQL database driver for [ClickHouse](https://clickhouse.com/). - -## Versions - -There are two version of this driver, v1 and v2, available as separate branches. - -**v1 is now in a state of a maintenance - we will only accept PRs for bug and security fixes.** - -Users should use v2 which is production ready and [significantly faster than v1](#benchmark). - -## Supported ClickHouse Versions - -The driver is tested against the currently [supported versions](https://github.com/ClickHouse/ClickHouse/blob/master/SECURITY.md) of ClickHouse - -## Key features - -* Uses native ClickHouse TCP client-server protocol -* Compatibility with [`database/sql`](#std-databasesql-interface) ([slower](#benchmark) than [native interface](#native-interface)!) -* Marshal rows into structs ([ScanStruct](tests/scan_struct_test.go), [Select](examples/native/scan_struct/main.go)) -* Unmarshal struct to row ([AppendStruct](benchmark/v2/write-native-struct/main.go)) -* Connection pool -* Failover and load balancing -* [Bulk write support](examples/native/batch/main.go) (for `database/sql` [use](examples/std/batch/main.go) `begin->prepare->(in loop exec)->commit`) -* [AsyncInsert](benchmark/v2/write-async/main.go) -* Named and numeric placeholders support -* LZ4 compression support -* External data - -Support for the ClickHouse protocol advanced features using `Context`: - -* Query ID -* Quota Key -* Settings -* OpenTelemetry -* Execution events: - * Logs - * Progress - * Profile info - * Profile events - -# `database/sql` interface - -## OpenDB - -```go -conn := clickhouse.OpenDB(&clickhouse.Options{ - Addr: []string{"127.0.0.1:9999"}, - Auth: clickhouse.Auth{ - Database: "default", - Username: "default", - Password: "", - }, - TLS: &tls.Config{ - InsecureSkipVerify: true, - }, - Settings: clickhouse.Settings{ - "max_execution_time": 60, - }, - DialTimeout: 5 * time.Second, - Compression: &clickhouse.Compression{ - clickhouse.CompressionLZ4, - }, - Debug: true, -}) -conn.SetMaxIdleConns(5) -conn.SetMaxOpenConns(10) -conn.SetConnMaxLifetime(time.Hour) -``` -## DSN - -* hosts - comma-separated list of single address hosts for load-balancing and failover -* username/password - auth credentials -* database - select the current default database -* dial_timeout - a duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix such as "300ms", "1s". Valid time units are "ms", "s", "m". -* connection_open_strategy - random/in_order (default random). - * round-robin - choose a round-robin server from the set - * in_order - first live server is chosen in specified order -* debug - enable debug output (boolean value) -* compress - enable lz4 compression (boolean value) - -SSL/TLS parameters: - -* secure - establish secure connection (default is false) -* skip_verify - skip certificate verification (default is false) - -Example: - -```sh -clickhouse://username:password@host1:9000,host2:9000/database?dial_timeout=200ms&max_execution_time=60 -``` - -## Benchmark - -| [V1 (READ)](benchmark/v1/read/main.go) | [V2 (READ) std](benchmark/v2/read/main.go) | [V2 (READ) native](benchmark/v2/read-native/main.go) | -| -------------------------------------- | ------------------------------------------ | ---------------------------------------------------- | -| 1.218s | 924.390ms | 675.721ms | - - -| [V1 (WRITE)](benchmark/v1/write/main.go) | [V2 (WRITE) std](benchmark/v2/write/main.go) | [V2 (WRITE) native](benchmark/v2/write-native/main.go) | [V2 (WRITE) by column](benchmark/v2/write-native-columnar/main.go) | -| ---------------------------------------- | -------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------ | -| 1.899s | 1.177s | 699.203ms | 661.973ms | - - - -## Install - -```sh -go get -u github.com/ClickHouse/clickhouse-go/v2 -``` - -## Examples - -### native interface - -* [batch](examples/native/batch/main.go) -* [async insert](examples/native/write-async) -* [batch struct](examples/native/write-struct/main.go) -* [columnar](examples/native/write-columnar/main.go) -* [scan struct](examples/native/scan_struct/main.go) -* [bind params](examples/native/bind/main.go) - -### std `database/sql` interface - -* [batch](examples/std/batch/main.go) -* [async insert](examples/std/write-async) -* [open db](examples/std/open_db/main.go) -* [bind params](examples/std/bind/main.go) - - -#### A Note on TLS/SSL - -At a low level all driver connect methods (DSN/OpenDB/Open) will use the [Go tls package](https://pkg.go.dev/crypto/tls) to establish a secure connection. The driver knows to use TLS if the Options struct contains a non-nil tls.Config pointer. - -Setting secure in the DSN creates a minimal tls.Config struct with only the InsecureSkipVerify field set (either true or false). It is equivalent to this code: - -```go -conn := clickhouse.OpenDB(&clickhouse.Options{ - ... - TLS: &tls.Config{ - InsecureSkipVerify: false - } - ... - }) -``` -This minimal tls.Config is normally all that is necessary to connect to the secure native port (normally 9440) on a ClickHouse server. If the ClickHouse server does not have a valid certificate (expired, wrong host name, not signed by a publicly recognized root Certificate Authority), InsecureSkipVerify can be to `true`, but that is strongly discouraged. - -If additional TLS parameters are necessary the application code should set the desired fields in the tls.Config struct. That can include specific cipher suites, forcing a particular TLS version (like 1.2 or 1.3), adding an internal CA certificate chain, adding a client certificate (and private key) if required by the ClickHouse server, and most of the other options that come with a more specialized security setup. - -## Third-party alternatives - -* Database drivers: - * [mailru/go-clickhouse](https://github.com/mailru/go-clickhouse) (uses the HTTP protocol) - * [uptrace/go-clickhouse](https://github.com/uptrace/go-clickhouse) (uses the native TCP protocol with `database/sql`-like API) - * Drivers with columnar interface: - * [vahid-sohrabloo/chconn](https://github.com/vahid-sohrabloo/chconn) - * [go-faster/ch](https://github.com/go-faster/ch) - -* Insert collectors: - * [KittenHouse](https://github.com/YuriyNasretdinov/kittenhouse) - * [nikepan/clickhouse-bulk](https://github.com/nikepan/clickhouse-bulk) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/bind.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/bind.go deleted file mode 100644 index b406e0ec14..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/bind.go +++ /dev/null @@ -1,268 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - std_driver "database/sql/driver" - "fmt" - "reflect" - "regexp" - "strings" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/driver" -) - -func Named(name string, value interface{}) driver.NamedValue { - return driver.NamedValue{ - Name: name, - Value: value, - } -} - -var bindNumericRe = regexp.MustCompile(`\$[0-9]+`) -var bindPositionalRe = regexp.MustCompile(`[^\\][?]`) - -func bind(tz *time.Location, query string, args ...interface{}) (string, error) { - if len(args) == 0 { - return query, nil - } - var ( - haveNamed bool - haveNumeric bool - havePositional bool - ) - haveNumeric = bindNumericRe.MatchString(query) - havePositional = bindPositionalRe.MatchString(query) - if haveNumeric && havePositional { - return "", ErrBindMixedParamsFormats - } - for _, v := range args { - switch v.(type) { - case driver.NamedValue: - haveNamed = true - default: - } - if haveNamed && (haveNumeric || havePositional) { - return "", ErrBindMixedParamsFormats - } - } - if haveNamed { - return bindNamed(tz, query, args...) - } - if haveNumeric { - return bindNumeric(tz, query, args...) - } - return bindPositional(tz, query, args...) -} - -var bindPositionCharRe = regexp.MustCompile(`[?]`) - -func bindPositional(tz *time.Location, query string, args ...interface{}) (_ string, err error) { - var ( - unbind = make(map[int]struct{}) - params = make([]string, len(args)) - ) - for i, v := range args { - if fn, ok := v.(std_driver.Valuer); ok { - if v, err = fn.Value(); err != nil { - return "", nil - } - } - params[i], err = format(tz, v) - if err != nil { - return "", err - } - } - i := 0 - query = bindPositionalRe.ReplaceAllStringFunc(query, func(n string) string { - if i >= len(params) { - unbind[i] = struct{}{} - return "" - } - val := params[i] - i++ - return bindPositionCharRe.ReplaceAllStringFunc(n, func(m string) string { - return val - }) - }) - for param := range unbind { - return "", fmt.Errorf("have no arg for param ? at position %d", param) - } - // replace \? escape sequence - return strings.ReplaceAll(query, "\\?", "?"), nil -} - -func bindNumeric(tz *time.Location, query string, args ...interface{}) (_ string, err error) { - var ( - unbind = make(map[string]struct{}) - params = make(map[string]string) - ) - for i, v := range args { - if fn, ok := v.(std_driver.Valuer); ok { - if v, err = fn.Value(); err != nil { - return "", nil - } - } - val, err := format(tz, v) - if err != nil { - return "", err - } - params[fmt.Sprintf("$%d", i+1)] = val - } - query = bindNumericRe.ReplaceAllStringFunc(query, func(n string) string { - if _, found := params[n]; !found { - unbind[n] = struct{}{} - return "" - } - return params[n] - }) - for param := range unbind { - return "", fmt.Errorf("have no arg for %s param", param) - } - return query, nil -} - -var bindNamedRe = regexp.MustCompile(`@[a-zA-Z0-9\_]+`) - -func bindNamed(tz *time.Location, query string, args ...interface{}) (_ string, err error) { - var ( - unbind = make(map[string]struct{}) - params = make(map[string]string) - ) - for _, v := range args { - switch v := v.(type) { - case driver.NamedValue: - value := v.Value - if fn, ok := v.Value.(std_driver.Valuer); ok { - if value, err = fn.Value(); err != nil { - return "", err - } - } - val, err := format(tz, value) - if err != nil { - return "", err - } - params["@"+v.Name] = val - } - } - query = bindNamedRe.ReplaceAllStringFunc(query, func(n string) string { - if _, found := params[n]; !found { - unbind[n] = struct{}{} - return "" - } - return params[n] - }) - for param := range unbind { - return "", fmt.Errorf("have no arg for %q param", param) - } - return query, nil -} - -func format(tz *time.Location, v interface{}) (string, error) { - quote := func(v string) string { - return "'" + strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(v) + "'" - } - switch v := v.(type) { - case nil: - return "NULL", nil - case string: - return quote(v), nil - case time.Time: - switch v.Location().String() { - case "Local": - return fmt.Sprintf("toDateTime(%d)", v.Unix()), nil - case tz.String(): - return v.Format("toDateTime('2006-01-02 15:04:05')"), nil - } - return v.Format("toDateTime('2006-01-02 15:04:05', '" + v.Location().String() + "')"), nil - case []interface{}: // tuple - elements := make([]string, 0, len(v)) - for _, e := range v { - val, err := format(tz, e) - if err != nil { - return "", err - } - elements = append(elements, val) - } - return "(" + strings.Join(elements, ", ") + ")", nil - case [][]interface{}: - items := make([]string, 0, len(v)) - for _, t := range v { - val, err := format(tz, t) - if err != nil { - return "", err - } - items = append(items, val) - } - return strings.Join(items, ", "), nil - case fmt.Stringer: - return quote(v.String()), nil - } - switch v := reflect.ValueOf(v); v.Kind() { - case reflect.String: - return quote(v.String()), nil - case reflect.Slice: - values := make([]string, 0, v.Len()) - for i := 0; i < v.Len(); i++ { - val, err := format(tz, v.Index(i).Interface()) - if err != nil { - return "", err - } - values = append(values, val) - } - return strings.Join(values, ", "), nil - case reflect.Map: // map - values := make([]string, 0, len(v.MapKeys())) - for _, key := range v.MapKeys() { - name := fmt.Sprint(key.Interface()) - if key.Kind() == reflect.String { - name = fmt.Sprintf("'%s'", name) - } - val, err := format(tz, v.MapIndex(key).Interface()) - if err != nil { - return "", err - } - if v.MapIndex(key).Kind() == reflect.Slice { - // assume slices in maps are arrays - val = fmt.Sprintf("[%s]", val) - } - values = append(values, fmt.Sprintf("%s : %s", name, val)) - } - return "{" + strings.Join(values, ", ") + "}", nil - - } - return fmt.Sprint(v), nil -} - -func rebind(in []std_driver.NamedValue) []interface{} { - args := make([]interface{}, 0, len(in)) - for _, v := range in { - switch { - case len(v.Name) != 0: - args = append(args, driver.NamedValue{ - Name: v.Name, - Value: v.Value, - }) - - default: - args = append(args, v.Value) - } - } - return args -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse.go deleted file mode 100644 index 351cc6cfa6..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse.go +++ /dev/null @@ -1,279 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "errors" - "fmt" - "sync/atomic" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/contributors" - "github.com/ClickHouse/clickhouse-go/v2/lib/column" - "github.com/ClickHouse/clickhouse-go/v2/lib/driver" - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -type Conn = driver.Conn - -type ( - Progress = proto.Progress - Exception = proto.Exception - ProfileInfo = proto.ProfileInfo - ServerVersion = proto.ServerHandshake -) - -var ( - ErrBatchAlreadySent = errors.New("clickhouse: batch has already been sent") - ErrAcquireConnTimeout = errors.New("clickhouse: acquire conn timeout. you can increase the number of max open conn or the dial timeout") - ErrUnsupportedServerRevision = errors.New("clickhouse: unsupported server revision") - ErrBindMixedParamsFormats = errors.New("clickhouse [bind]: mixed named, numeric or positional parameters") - ErrAcquireConnNoAddress = errors.New("clickhouse: no valid address supplied") -) - -type OpError struct { - Op string - ColumnName string - Err error -} - -func (e *OpError) Error() string { - switch err := e.Err.(type) { - case *column.Error: - return fmt.Sprintf("clickhouse [%s]: (%s %s) %s", e.Op, e.ColumnName, err.ColumnType, err.Err) - case *column.ColumnConverterError: - var hint string - if len(err.Hint) != 0 { - hint += ". " + err.Hint - } - return fmt.Sprintf("clickhouse [%s]: (%s) converting %s to %s is unsupported%s", - err.Op, e.ColumnName, - err.From, err.To, - hint, - ) - } - return fmt.Sprintf("clickhouse [%s]: %s", e.Op, e.Err) -} - -func Open(opt *Options) (driver.Conn, error) { - opt.setDefaults() - return &clickhouse{ - opt: opt, - idle: make(chan *connect, opt.MaxIdleConns), - open: make(chan struct{}, opt.MaxOpenConns), - }, nil -} - -type clickhouse struct { - opt *Options - idle chan *connect - open chan struct{} - connID int64 -} - -func (clickhouse) Contributors() []string { - list := contributors.List - if len(list[len(list)-1]) == 0 { - return list[:len(list)-1] - } - return list -} - -func (ch *clickhouse) ServerVersion() (*driver.ServerVersion, error) { - var ( - ctx, cancel = context.WithTimeout(context.Background(), ch.opt.DialTimeout) - conn, err = ch.acquire(ctx) - ) - defer cancel() - if err != nil { - return nil, err - } - ch.release(conn, nil) - return &conn.server, nil -} - -func (ch *clickhouse) Query(ctx context.Context, query string, args ...interface{}) (rows driver.Rows, err error) { - conn, err := ch.acquire(ctx) - if err != nil { - return nil, err - } - return conn.query(ctx, ch.release, query, args...) -} - -func (ch *clickhouse) QueryRow(ctx context.Context, query string, args ...interface{}) (rows driver.Row) { - conn, err := ch.acquire(ctx) - if err != nil { - return &row{ - err: err, - } - } - return conn.queryRow(ctx, ch.release, query, args...) -} - -func (ch *clickhouse) Exec(ctx context.Context, query string, args ...interface{}) error { - conn, err := ch.acquire(ctx) - if err != nil { - return err - } - if err := conn.exec(ctx, query, args...); err != nil { - ch.release(conn, err) - return err - } - ch.release(conn, nil) - return nil -} - -func (ch *clickhouse) PrepareBatch(ctx context.Context, query string) (driver.Batch, error) { - conn, err := ch.acquire(ctx) - if err != nil { - return nil, err - } - batch, err := conn.prepareBatch(ctx, query, ch.release) - if err != nil { - return nil, err - } - return batch, nil -} - -func (ch *clickhouse) AsyncInsert(ctx context.Context, query string, wait bool) error { - conn, err := ch.acquire(ctx) - if err != nil { - return err - } - if err := conn.asyncInsert(ctx, query, wait); err != nil { - ch.release(conn, err) - return err - } - ch.release(conn, nil) - return nil -} - -func (ch *clickhouse) Ping(ctx context.Context) (err error) { - conn, err := ch.acquire(ctx) - if err != nil { - return err - } - if err := conn.ping(ctx); err != nil { - ch.release(conn, err) - return err - } - ch.release(conn, nil) - return nil -} - -func (ch *clickhouse) Stats() driver.Stats { - return driver.Stats{ - Open: len(ch.open), - Idle: len(ch.idle), - MaxOpenConns: cap(ch.open), - MaxIdleConns: cap(ch.idle), - } -} - -func (ch *clickhouse) dial(ctx context.Context) (conn *connect, err error) { - connID := int(atomic.AddInt64(&ch.connID, 1)) - for i := range ch.opt.Addr { - var num int - switch ch.opt.ConnOpenStrategy { - case ConnOpenInOrder: - num = i - case ConnOpenRoundRobin: - num = (int(connID) + i) % len(ch.opt.Addr) - } - if conn, err = dial(ctx, ch.opt.Addr[num], connID, ch.opt); err == nil { - return conn, nil - } - } - if err == nil { - err = ErrAcquireConnNoAddress - } - return nil, err -} - -func (ch *clickhouse) acquire(ctx context.Context) (conn *connect, err error) { - timer := time.NewTimer(ch.opt.DialTimeout) - defer timer.Stop() - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - } - select { - case <-timer.C: - return nil, ErrAcquireConnTimeout - case ch.open <- struct{}{}: - } - select { - case <-timer.C: - return nil, ErrAcquireConnTimeout - case conn := <-ch.idle: - if conn.isBad() { - conn.close() - if conn, err = ch.dial(ctx); err != nil { - select { - case <-ch.open: - default: - } - return nil, err - } - } - conn.released = false - return conn, nil - default: - } - if conn, err = ch.dial(ctx); err != nil { - select { - case <-ch.open: - default: - } - return nil, err - } - return conn, nil -} - -func (ch *clickhouse) release(conn *connect, err error) { - if conn.released { - return - } - conn.released = true - select { - case <-ch.open: - default: - } - if err != nil || time.Since(conn.connectedAt) >= ch.opt.ConnMaxLifetime { - conn.close() - return - } - select { - case ch.idle <- conn: - default: - conn.close() - } -} - -func (ch *clickhouse) Close() error { - for { - select { - case c := <-ch.idle: - c.close() - default: - return nil - } - } -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_options.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_options.go deleted file mode 100644 index e70cdcff7d..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_options.go +++ /dev/null @@ -1,162 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "crypto/tls" - "fmt" - "net" - "net/url" - "strconv" - "strings" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/compress" -) - -var CompressionLZ4 compress.Method = compress.LZ4 - -type Auth struct { // has_control_character - Database string - Username string - Password string -} - -type Compression struct { - Method compress.Method -} - -type ConnOpenStrategy uint8 - -const ( - ConnOpenInOrder ConnOpenStrategy = iota - ConnOpenRoundRobin -) - -func ParseDSN(dsn string) (*Options, error) { - opt := &Options{} - if err := opt.fromDSN(dsn); err != nil { - return nil, err - } - return opt, nil -} - -type Options struct { - TLS *tls.Config - Addr []string - Auth Auth - DialContext func(ctx context.Context, addr string) (net.Conn, error) - Debug bool - Debugf func(format string, v ...interface{}) // only works when Debug is true - Settings Settings - Compression *Compression - DialTimeout time.Duration // default 1 second - MaxOpenConns int // default MaxIdleConns + 5 - MaxIdleConns int // default 5 - ConnMaxLifetime time.Duration // default 1 hour - ConnOpenStrategy ConnOpenStrategy -} - -func (o *Options) fromDSN(in string) error { - dsn, err := url.Parse(in) - if err != nil { - return err - } - if o.Settings == nil { - o.Settings = make(Settings) - } - if dsn.User != nil { - o.Auth.Username = dsn.User.Username() - o.Auth.Password, _ = dsn.User.Password() - } - o.Addr = append(o.Addr, strings.Split(dsn.Host, ",")...) - var ( - secure bool - params = dsn.Query() - skipVerify bool - ) - o.Auth.Database = strings.TrimPrefix(dsn.Path, "/") - for v := range params { - switch v { - case "debug": - o.Debug, _ = strconv.ParseBool(params.Get(v)) - case "compress": - if on, _ := strconv.ParseBool(params.Get(v)); on { - o.Compression = &Compression{ - Method: CompressionLZ4, - } - } - case "dial_timeout": - duration, err := time.ParseDuration(params.Get(v)) - if err != nil { - return fmt.Errorf("clickhouse [dsn parse]: dial timeout: %s", err) - } - o.DialTimeout = duration - case "secure": - secure = true - case "skip_verify": - skipVerify = true - case "connection_open_strategy": - switch params.Get(v) { - case "in_order": - o.ConnOpenStrategy = ConnOpenInOrder - case "round_robin": - o.ConnOpenStrategy = ConnOpenRoundRobin - } - default: - switch p := strings.ToLower(params.Get(v)); p { - case "true": - o.Settings[v] = int(1) - case "false": - o.Settings[v] = int(0) - default: - if n, err := strconv.Atoi(p); err == nil { - o.Settings[v] = n - } - } - } - } - if secure { - o.TLS = &tls.Config{ - InsecureSkipVerify: skipVerify, - } - } - return nil -} - -func (o *Options) setDefaults() { - if len(o.Auth.Database) == 0 { - o.Auth.Database = "default" - } - if len(o.Auth.Username) == 0 { - o.Auth.Username = "default" - } - if o.DialTimeout == 0 { - o.DialTimeout = time.Second - } - if o.MaxIdleConns <= 0 { - o.MaxIdleConns = 5 - } - if o.MaxOpenConns <= 0 { - o.MaxOpenConns = o.MaxIdleConns + 5 - } - if o.ConnMaxLifetime == 0 { - o.ConnMaxLifetime = time.Hour - } -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_rows.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_rows.go deleted file mode 100644 index 2b0bd37130..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_rows.go +++ /dev/null @@ -1,161 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "database/sql" - "io" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -type rows struct { - err error - row int - block *proto.Block - totals *proto.Block - errors chan error - stream chan *proto.Block - columns []string - structMap *structMap -} - -func (r *rows) Next() (result bool) { - defer func() { - if !result { - r.Close() - } - }() - if r.block == nil { - return false - } -next: - if r.row >= r.block.Rows() { - select { - case err := <-r.errors: - if err != nil { - r.err = err - return false - } - goto next - case block := <-r.stream: - if block == nil { - return false - } - if block.Packet == proto.ServerTotals { - r.row, r.block, r.totals = 0, nil, block - return false - } - r.row, r.block = 0, block - } - } - r.row++ - return r.row <= r.block.Rows() -} - -func (r *rows) Scan(dest ...interface{}) error { - if r.block == nil || (r.row == 0 && r.row >= r.block.Rows()) { // call without next when result is empty - return io.EOF - } - return scan(r.block, r.row, dest...) -} - -func (r *rows) ScanStruct(dest interface{}) error { - values, err := r.structMap.Map("ScanStruct", r.columns, dest, true) - if err != nil { - return err - } - return r.Scan(values...) -} - -func (r *rows) Totals(dest ...interface{}) error { - if r.totals == nil { - return sql.ErrNoRows - } - return scan(r.totals, 1, dest...) -} - -func (r *rows) Columns() []string { - return r.columns -} - -func (r *rows) Close() error { - active := 2 - for { - select { - case _, ok := <-r.stream: - if !ok { - active-- - if active == 0 { - return r.err - } - } - case err, ok := <-r.errors: - if err != nil { - r.err = err - } - if !ok { - active-- - if active == 0 { - return r.err - } - } - } - } -} - -func (r *rows) Err() error { - return r.err -} - -type row struct { - err error - rows *rows -} - -func (r *row) Err() error { - return r.err -} - -func (r *row) ScanStruct(dest interface{}) error { - if r.err != nil { - return r.err - } - values, err := r.rows.structMap.Map("ScanStruct", r.rows.columns, dest, true) - if err != nil { - return err - } - return r.Scan(values...) -} - -func (r *row) Scan(dest ...interface{}) error { - if r.err != nil { - return r.err - } - if !r.rows.Next() { - r.rows.Close() - if err := r.rows.Err(); err != nil { - return err - } - return sql.ErrNoRows - } - if err := r.rows.Scan(dest...); err != nil { - return err - } - return r.rows.Close() -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_rows_column_type.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_rows_column_type.go deleted file mode 100644 index d0719e72f3..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_rows_column_type.go +++ /dev/null @@ -1,62 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/column" - "github.com/ClickHouse/clickhouse-go/v2/lib/driver" -) - -type columnType struct { - name string - chType string - nullable bool - scanType reflect.Type -} - -func (c *columnType) Name() string { - return c.name -} - -func (c *columnType) Nullable() bool { - return c.nullable -} - -func (c *columnType) ScanType() reflect.Type { - return c.scanType -} - -func (c *columnType) DatabaseTypeName() string { - return c.chType -} - -func (r *rows) ColumnTypes() []driver.ColumnType { - types := make([]driver.ColumnType, 0, len(r.columns)) - for i, c := range r.block.Columns { - _, nullable := c.(*column.Nullable) - types = append(types, &columnType{ - name: r.columns[i], - chType: string(c.Type()), - nullable: nullable, - scanType: c.ScanType(), - }) - } - return types -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_std.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_std.go deleted file mode 100644 index 12e99d7c0b..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/clickhouse_std.go +++ /dev/null @@ -1,289 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "database/sql" - "database/sql/driver" - "errors" - "fmt" - "io" - "reflect" - "strings" - "sync/atomic" - - "github.com/ClickHouse/clickhouse-go/v2/lib/column" -) - -var globalConnID int64 - -type stdConnOpener struct { - err error - opt *Options -} - -func (o *stdConnOpener) Driver() driver.Driver { - return &stdDriver{} -} - -func (o *stdConnOpener) Connect(ctx context.Context) (_ driver.Conn, err error) { - if o.err != nil { - return nil, o.err - } - var ( - conn *connect - connID = int(atomic.AddInt64(&globalConnID, 1)) - ) - for i := range o.opt.Addr { - var num int - switch o.opt.ConnOpenStrategy { - case ConnOpenInOrder: - num = i - case ConnOpenRoundRobin: - num = (int(connID) + i) % len(o.opt.Addr) - } - if conn, err = dial(ctx, o.opt.Addr[num], connID, o.opt); err == nil { - return &stdDriver{ - conn: conn, - }, nil - } - } - return nil, err -} - -func init() { - sql.Register("clickhouse", &stdDriver{}) -} - -func OpenDB(opt *Options) *sql.DB { - var settings []string - if opt.MaxIdleConns > 0 { - settings = append(settings, "SetMaxIdleConns") - } - if opt.MaxOpenConns > 0 { - settings = append(settings, "SetMaxOpenConns") - } - if opt.ConnMaxLifetime > 0 { - settings = append(settings, "SetConnMaxLifetime") - } - if len(settings) != 0 { - return sql.OpenDB(&stdConnOpener{ - err: fmt.Errorf("cannot connect. invalid settings. use %s (see https://pkg.go.dev/database/sql)", strings.Join(settings, ",")), - }) - } - opt.setDefaults() - return sql.OpenDB(&stdConnOpener{ - opt: opt, - }) -} - -type stdDriver struct { - conn *connect - commit func() error -} - -func (d *stdDriver) Open(dsn string) (_ driver.Conn, err error) { - var opt Options - if err := opt.fromDSN(dsn); err != nil { - return nil, err - } - opt.setDefaults() - return (&stdConnOpener{opt: &opt}).Connect(context.Background()) -} - -func (std *stdDriver) ResetSession(ctx context.Context) error { - if std.conn.isBad() { - return driver.ErrBadConn - } - return nil -} - -func (std *stdDriver) Ping(ctx context.Context) error { return std.conn.ping(ctx) } - -func (std *stdDriver) Begin() (driver.Tx, error) { return std, nil } - -func (std *stdDriver) Commit() error { - if std.commit == nil { - return nil - } - defer func() { - std.commit = nil - }() - return std.commit() -} - -func (std *stdDriver) Rollback() error { - std.commit = nil - std.conn.close() - return nil -} - -func (std *stdDriver) CheckNamedValue(nv *driver.NamedValue) error { return nil } - -func (std *stdDriver) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { - if options := queryOptions(ctx); options.async.ok { - if len(args) != 0 { - return nil, errors.New("clickhouse: you can't use parameters in an asynchronous insert") - } - return driver.RowsAffected(0), std.conn.asyncInsert(ctx, query, options.async.wait) - } - if err := std.conn.exec(ctx, query, rebind(args)...); err != nil { - return nil, err - } - return driver.RowsAffected(0), nil -} - -func (std *stdDriver) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { - r, err := std.conn.query(ctx, func(*connect, error) {}, query, rebind(args)...) - if err != nil { - return nil, err - } - return &stdRows{ - rows: r, - }, nil -} - -func (std *stdDriver) Prepare(query string) (driver.Stmt, error) { - return std.PrepareContext(context.Background(), query) -} - -func (std *stdDriver) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { - batch, err := std.conn.prepareBatch(ctx, query, func(*connect, error) {}) - if err != nil { - return nil, err - } - std.commit = batch.Send - return &stdBatch{ - batch: batch, - }, nil -} - -func (std *stdDriver) Close() error { return std.conn.close() } - -type stdBatch struct { - batch *batch -} - -func (s *stdBatch) NumInput() int { return -1 } -func (s *stdBatch) Exec(args []driver.Value) (driver.Result, error) { - values := make([]interface{}, 0, len(args)) - for _, v := range args { - values = append(values, v) - } - if err := s.batch.Append(values...); err != nil { - return nil, err - } - return driver.RowsAffected(0), nil -} - -func (s *stdBatch) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) { - values := make([]driver.Value, 0, len(args)) - for _, v := range args { - values = append(values, v.Value) - } - return s.Exec(values) -} - -func (s *stdBatch) Query(args []driver.Value) (driver.Rows, error) { - return nil, errors.New("only Exec method supported in batch mode") -} - -func (s *stdBatch) Close() error { return nil } - -type stdRows struct { - rows *rows -} - -func (r *stdRows) Columns() []string { - return r.rows.Columns() -} - -func (r *stdRows) ColumnTypeScanType(idx int) reflect.Type { - return r.rows.block.Columns[idx].ScanType() -} - -func (r *stdRows) ColumnTypeDatabaseTypeName(idx int) string { - return string(r.rows.block.Columns[idx].Type()) -} - -func (r *stdRows) ColumnTypeNullable(idx int) (nullable, ok bool) { - _, ok = r.rows.block.Columns[idx].(*column.Nullable) - return ok, true -} - -func (r *stdRows) ColumnTypePrecisionScale(idx int) (precision, scale int64, ok bool) { - switch col := r.rows.block.Columns[idx].(type) { - case *column.Decimal: - return col.Precision(), col.Scale(), true - case interface{ Base() column.Interface }: - switch col := col.Base().(type) { - case *column.Decimal: - return col.Precision(), col.Scale(), true - } - } - return 0, 0, false -} - -func (r *stdRows) Next(dest []driver.Value) error { - if len(r.rows.block.Columns) != len(dest) { - return &OpError{ - Op: "Next", - Err: fmt.Errorf("expected %d destination arguments in Next, not %d", len(r.rows.block.Columns), len(dest)), - } - } - if r.rows.Next() { - for i := range dest { - nullable, ok := r.ColumnTypeNullable(i) - switch value := r.rows.block.Columns[i].Row(r.rows.row-1, nullable && ok).(type) { - case driver.Valuer: - v, err := value.Value() - if err != nil { - return err - } - dest[i] = v - default: - dest[i] = value - } - } - return nil - } - if err := r.rows.Err(); err != nil { - return err - } - return io.EOF -} - -func (r *stdRows) HasNextResultSet() bool { - return r.rows.totals != nil -} - -func (r *stdRows) NextResultSet() error { - switch { - case r.rows.totals != nil: - r.rows.block = r.rows.totals - r.rows.totals = nil - default: - return io.EOF - } - return nil -} - -func (r *stdRows) Close() error { - return r.rows.Close() -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn.go deleted file mode 100644 index a38548dd7e..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn.go +++ /dev/null @@ -1,197 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "crypto/tls" - "fmt" - "log" - "net" - "os" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/ClickHouse/clickhouse-go/v2/lib/io" - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -func dial(ctx context.Context, addr string, num int, opt *Options) (*connect, error) { - var ( - err error - conn net.Conn - debugf = func(format string, v ...interface{}) {} - ) - switch { - case opt.DialContext != nil: - conn, err = opt.DialContext(ctx, addr) - default: - switch { - case opt.TLS != nil: - conn, err = tls.DialWithDialer(&net.Dialer{Timeout: opt.DialTimeout}, "tcp", addr, opt.TLS) - default: - conn, err = net.DialTimeout("tcp", addr, opt.DialTimeout) - } - } - if err != nil { - return nil, err - } - if opt.Debug { - if opt.Debugf != nil { - debugf = opt.Debugf - } else { - debugf = log.New(os.Stdout, fmt.Sprintf("[clickhouse][conn=%d][%s]", num, conn.RemoteAddr()), 0).Printf - } - } - var compression bool - if opt.Compression != nil { - compression = opt.Compression.Method == CompressionLZ4 - } - var ( - stream = io.NewStream(conn) - connect = &connect{ - opt: opt, - conn: conn, - debugf: debugf, - stream: stream, - encoder: binary.NewEncoder(stream), - decoder: binary.NewDecoder(stream), - revision: proto.ClientTCPProtocolVersion, - structMap: &structMap{}, - compression: compression, - connectedAt: time.Now(), - } - ) - if err := connect.handshake(opt.Auth.Database, opt.Auth.Username, opt.Auth.Password); err != nil { - return nil, err - } - return connect, nil -} - -// https://github.com/ClickHouse/ClickHouse/blob/master/src/Client/Connection.cpp -type connect struct { - opt *Options - conn net.Conn - debugf func(format string, v ...interface{}) - server ServerVersion - stream *io.Stream - closed bool - encoder *binary.Encoder - decoder *binary.Decoder - released bool - revision uint64 - structMap *structMap - compression bool - // lastUsedIn time.Time - connectedAt time.Time -} - -func (c *connect) settings(querySettings Settings) []proto.Setting { - settings := make([]proto.Setting, 0, len(c.opt.Settings)+len(querySettings)) - for k, v := range c.opt.Settings { - settings = append(settings, proto.Setting{ - Key: k, - Value: v, - }) - } - for k, v := range querySettings { - settings = append(settings, proto.Setting{ - Key: k, - Value: v, - }) - } - return settings -} - -func (c *connect) isBad() bool { - switch { - case c.closed: - return true - } - if err := c.connCheck(); err != nil { - return true - } - return false -} - -func (c *connect) close() error { - if c.closed { - return nil - } - c.closed = true - c.encoder = nil - c.decoder = nil - c.stream.Close() - if err := c.conn.Close(); err != nil { - return err - } - return nil -} - -func (c *connect) progress() (*Progress, error) { - var progress proto.Progress - if err := progress.Decode(c.decoder, c.revision); err != nil { - return nil, err - } - c.debugf("[progress] %s", &progress) - return &progress, nil -} - -func (c *connect) exception() error { - var e Exception - if err := e.Decode(c.decoder); err != nil { - return err - } - c.debugf("[exception] %s", e.Error()) - return &e -} - -func (c *connect) sendData(block *proto.Block, name string) error { - c.debugf("[send data] compression=%t", c.compression) - if err := c.encoder.Byte(proto.ClientData); err != nil { - return err - } - if err := c.encoder.String(name); err != nil { - return err - } - if c.compression { - c.stream.Compress(true) - defer func() { - c.stream.Compress(false) - c.encoder.Flush() - }() - } - return block.Encode(c.encoder, c.revision) -} - -func (c *connect) readData(packet byte, compressible bool) (*proto.Block, error) { - if _, err := c.decoder.String(); err != nil { - return nil, err - } - if compressible && c.compression { - c.stream.Compress(true) - defer c.stream.Compress(false) - } - var block proto.Block - if err := block.Decode(c.decoder, c.revision); err != nil { - return nil, err - } - block.Packet = packet - c.debugf("[read data] compression=%t. block: columns=%d, rows=%d", c.compression, len(block.Columns), block.Rows()) - return &block, nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_async_insert.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_async_insert.go deleted file mode 100644 index a324bd1da6..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_async_insert.go +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" -) - -func (c *connect) asyncInsert(ctx context.Context, query string, wait bool) error { - options := queryOptions(ctx) - { - options.settings["async_insert"] = 1 - options.settings["wait_for_async_insert"] = 0 - if wait { - options.settings["wait_for_async_insert"] = 1 - } - } - if err := c.sendQuery(query, &options); err != nil { - return err - } - return c.process(ctx, options.onProcess()) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_batch.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_batch.go deleted file mode 100644 index c2af6204f5..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_batch.go +++ /dev/null @@ -1,181 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "fmt" - "os" - "regexp" - "strings" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/column" - "github.com/ClickHouse/clickhouse-go/v2/lib/driver" - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -var splitInsertRe = regexp.MustCompile(`(?i)\sVALUES\s*\(`) - -func (c *connect) prepareBatch(ctx context.Context, query string, release func(*connect, error)) (*batch, error) { - query = splitInsertRe.Split(query, -1)[0] - if !strings.HasSuffix(strings.TrimSpace(strings.ToUpper(query)), "VALUES") { - query += " VALUES" - } - options := queryOptions(ctx) - if deadline, ok := ctx.Deadline(); ok { - c.conn.SetDeadline(deadline) - defer c.conn.SetDeadline(time.Time{}) - } - if err := c.sendQuery(query, &options); err != nil { - release(c, err) - return nil, err - } - var ( - onProcess = options.onProcess() - block, err = c.firstBlock(ctx, onProcess) - ) - if err != nil { - release(c, err) - return nil, err - } - return &batch{ - ctx: ctx, - conn: c, - block: block, - release: func(err error) { - release(c, err) - }, - onProcess: onProcess, - }, nil -} - -type batch struct { - err error - ctx context.Context - conn *connect - sent bool - block *proto.Block - release func(error) - onProcess *onProcess -} - -func (b *batch) Abort() error { - defer func() { - b.sent = true - b.release(os.ErrProcessDone) - }() - if b.sent { - return ErrBatchAlreadySent - } - return nil -} - -func (b *batch) Append(v ...interface{}) error { - if b.sent { - return ErrBatchAlreadySent - } - if err := b.block.Append(v...); err != nil { - b.release(err) - return err - } - return nil -} - -func (b *batch) AppendStruct(v interface{}) error { - values, err := b.conn.structMap.Map("AppendStruct", b.block.ColumnsNames(), v, false) - if err != nil { - return err - } - return b.Append(values...) -} - -func (b *batch) Column(idx int) driver.BatchColumn { - if len(b.block.Columns) <= idx { - b.release(nil) - return &batchColumn{ - err: &OpError{ - Op: "batch.Column", - Err: fmt.Errorf("invalid column index %d", idx), - }, - } - } - return &batchColumn{ - batch: b, - column: b.block.Columns[idx], - release: func(err error) { - b.err = err - b.release(err) - }, - } -} - -func (b *batch) Send() (err error) { - defer func() { - b.sent = true - b.release(err) - }() - if b.sent { - return ErrBatchAlreadySent - } - if b.err != nil { - return b.err - } - if b.block.Rows() != 0 { - if err = b.conn.sendData(b.block, ""); err != nil { - return err - } - } - if err = b.conn.sendData(&proto.Block{}, ""); err != nil { - return err - } - if err = b.conn.encoder.Flush(); err != nil { - return err - } - if err = b.conn.process(b.ctx, b.onProcess); err != nil { - return err - } - return nil -} - -type batchColumn struct { - err error - batch *batch - column column.Interface - release func(error) -} - -func (b *batchColumn) Append(v interface{}) (err error) { - if b.batch.sent { - return ErrBatchAlreadySent - } - if b.err != nil { - b.release(b.err) - return b.err - } - if _, err = b.column.Append(v); err != nil { - b.release(err) - return err - } - return nil -} - -var ( - _ (driver.Batch) = (*batch)(nil) - _ (driver.BatchColumn) = (*batchColumn)(nil) -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_check.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_check.go deleted file mode 100644 index f30194f847..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_check.go +++ /dev/null @@ -1,60 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos -// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos - -package clickhouse - -import ( - "errors" - "io" - "syscall" -) - -func (c *connect) connCheck() error { - var sysErr error - sysConn, ok := c.conn.(syscall.Conn) - if !ok { - return nil - } - rawConn, err := sysConn.SyscallConn() - if err != nil { - return err - } - - err = rawConn.Read(func(fd uintptr) bool { - var buf [1]byte - n, err := syscall.Read(int(fd), buf[:]) - switch { - case n == 0 && err == nil: - sysErr = io.EOF - case n > 0: - sysErr = errors.New("unexpected read from socket") - case err == syscall.EAGAIN || err == syscall.EWOULDBLOCK: - sysErr = nil - default: - sysErr = err - } - return true - }) - if err != nil { - return err - } - - return sysErr -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_check_ping.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_check_ping.go deleted file mode 100644 index fe1fe7bfaa..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_check_ping.go +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !illumos -// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos - -package clickhouse - -import ( - "context" - "time" -) - -func (c *connect) connCheck() error { - ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second)) - defer cancel() - if err := c.ping(ctx); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_exec.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_exec.go deleted file mode 100644 index 433aba7733..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_exec.go +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "time" -) - -func (c *connect) exec(ctx context.Context, query string, args ...interface{}) error { - var ( - options = queryOptions(ctx) - body, err = bind(c.server.Timezone, query, args...) - ) - if err != nil { - return err - } - if deadline, ok := ctx.Deadline(); ok { - c.conn.SetDeadline(deadline) - defer c.conn.SetDeadline(time.Time{}) - } - if err := c.sendQuery(body, &options); err != nil { - return err - } - return c.process(ctx, options.onProcess()) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_handshake.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_handshake.go deleted file mode 100644 index 09af51c5d2..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_handshake.go +++ /dev/null @@ -1,79 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "fmt" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -func (c *connect) handshake(database, username, password string) error { - c.debugf("[handshake] -> %s", proto.ClientHandshake{}) - c.conn.SetDeadline(time.Now().Add(c.opt.DialTimeout)) - defer c.conn.SetDeadline(time.Time{}) - { - c.encoder.Byte(proto.ClientHello) - if err := (&proto.ClientHandshake{}).Encode(c.encoder); err != nil { - return err - } - { - if err := c.encoder.String(database); err != nil { - return err - } - if err := c.encoder.String(username); err != nil { - return err - } - if err := c.encoder.String(password); err != nil { - return err - } - } - if err := c.encoder.Flush(); err != nil { - return err - } - } - { - packet, err := c.decoder.ReadByte() - if err != nil { - return err - } - switch packet { - case proto.ServerException: - return c.exception() - case proto.ServerHello: - if err := c.server.Decode(c.decoder); err != nil { - return err - } - case proto.ServerEndOfStream: - c.debugf("[handshake] <- end of stream") - return nil - default: - return fmt.Errorf("[handshake] unexpected packet [%d] from server", packet) - } - } - if c.server.Revision < proto.DBMS_MIN_REVISION_WITH_CLIENT_INFO { - return ErrUnsupportedServerRevision - } - if c.revision > c.server.Revision { - c.revision = c.server.Revision - c.debugf("[handshake] downgrade client proto") - } - c.debugf("[handshake] <- %s", c.server) - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_logs.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_logs.go deleted file mode 100644 index 4f234ccfb3..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_logs.go +++ /dev/null @@ -1,88 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -type Log struct { - Time time.Time - TimeMicro uint32 - Hostname string - QueryID string - ThreadID uint64 - Priority int8 - Source string - Text string -} - -func (c *connect) logs() ([]Log, error) { - block, err := c.readData(proto.ServerLog, false) - if err != nil { - return nil, err - } - c.debugf("[logs] rows=%d", block.Rows()) - var ( - logs []Log - names = block.ColumnsNames() - ) - for r := 0; r < block.Rows(); r++ { - var log Log - for i, b := range block.Columns { - switch names[i] { - case "event_time": - if err := b.ScanRow(&log.Time, r); err != nil { - return nil, err - } - case "event_time_microseconds": - if err := b.ScanRow(&log.TimeMicro, r); err != nil { - return nil, err - } - case "host_name": - if err := b.ScanRow(&log.Hostname, r); err != nil { - return nil, err - } - case "query_id": - if err := b.ScanRow(&log.QueryID, r); err != nil { - return nil, err - } - case "thread_id": - if err := b.ScanRow(&log.ThreadID, r); err != nil { - return nil, err - } - case "priority": - if err := b.ScanRow(&log.Priority, r); err != nil { - return nil, err - } - case "source": - if err := b.ScanRow(&log.Source, r); err != nil { - return nil, err - } - case "text": - if err := b.ScanRow(&log.Text, r); err != nil { - return nil, err - } - } - } - logs = append(logs, log) - } - return logs, nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_ping.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_ping.go deleted file mode 100644 index 8426f34cf9..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_ping.go +++ /dev/null @@ -1,61 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "fmt" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -// Connection::ping -// https://github.com/ClickHouse/ClickHouse/blob/master/src/Client/Connection.cpp -func (c *connect) ping(ctx context.Context) (err error) { - if deadline, ok := ctx.Deadline(); ok { - c.conn.SetDeadline(deadline) - defer c.conn.SetDeadline(time.Time{}) - } - c.debugf("[ping] -> ping") - if err := c.encoder.Byte(proto.ClientPing); err != nil { - return err - } - if err := c.encoder.Flush(); err != nil { - return err - } - var packet byte - for { - if packet, err = c.decoder.ReadByte(); err != nil { - return err - } - switch packet { - case proto.ServerException: - return c.exception() - case proto.ServerProgress: - if _, err = c.progress(); err != nil { - return err - } - case proto.ServerPong: - c.debugf("[ping] <- pong") - return nil - default: - return fmt.Errorf("unexpected packet %d", packet) - } - } -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_process.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_process.go deleted file mode 100644 index 88928c264f..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_process.go +++ /dev/null @@ -1,147 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "fmt" - "io" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -type onProcess struct { - data func(*proto.Block) - logs func([]Log) - progress func(*Progress) - profileInfo func(*ProfileInfo) - profileEvents func([]ProfileEvent) -} - -func (c *connect) firstBlock(ctx context.Context, on *onProcess) (*proto.Block, error) { - for { - select { - case <-ctx.Done(): - c.cancel() - return nil, ctx.Err() - default: - } - packet, err := c.decoder.ReadByte() - if err != nil { - return nil, err - } - switch packet { - case proto.ServerData: - return c.readData(packet, true) - case proto.ServerEndOfStream: - c.debugf("[end of stream]") - return nil, io.EOF - default: - if err := c.handle(packet, on); err != nil { - return nil, err - } - } - } -} - -func (c *connect) process(ctx context.Context, on *onProcess) error { - for { - select { - case <-ctx.Done(): - c.cancel() - return ctx.Err() - default: - } - packet, err := c.decoder.ReadByte() - if err != nil { - return err - } - switch packet { - case proto.ServerEndOfStream: - c.debugf("[end of stream]") - return nil - } - if err := c.handle(packet, on); err != nil { - return err - } - } -} - -func (c *connect) handle(packet byte, on *onProcess) error { - switch packet { - case proto.ServerData, proto.ServerTotals, proto.ServerExtremes: - block, err := c.readData(packet, true) - if err != nil { - return err - } - if block.Rows() != 0 && on.data != nil { - on.data(block) - } - case proto.ServerException: - return c.exception() - case proto.ServerProfileInfo: - var info proto.ProfileInfo - if err := info.Decode(c.decoder, c.revision); err != nil { - return err - } - c.debugf("[profile info] %s", &info) - on.profileInfo(&info) - case proto.ServerTableColumns: - var info proto.TableColumns - if err := info.Decode(c.decoder, c.revision); err != nil { - return err - } - c.debugf("[table columns]") - case proto.ServerProfileEvents: - events, err := c.profileEvents() - if err != nil { - return err - } - on.profileEvents(events) - case proto.ServerLog: - logs, err := c.logs() - if err != nil { - return err - } - on.logs(logs) - case proto.ServerProgress: - progress, err := c.progress() - if err != nil { - return err - } - c.debugf("[progress] %s", progress) - on.progress(progress) - default: - return &OpError{ - Op: "process", - Err: fmt.Errorf("unexpected packet %d", packet), - } - } - return nil -} - -func (c *connect) cancel() error { - c.conn.SetDeadline(time.Now().Add(2 * time.Second)) - c.debugf("[cancel]") - c.closed = true - if err := c.encoder.Uvarint(proto.ClientCancel); err == nil { - return err - } - return c.encoder.Flush() -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_profile_events.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_profile_events.go deleted file mode 100644 index 3fa7db74d6..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_profile_events.go +++ /dev/null @@ -1,88 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "reflect" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -type ProfileEvent struct { - Hostname string - CurrentTime time.Time - ThreadID uint64 - Type string - Name string - Value int64 -} - -func (c *connect) profileEvents() ([]ProfileEvent, error) { - block, err := c.readData(proto.ServerProfileEvents, false) - if err != nil { - return nil, err - } - c.debugf("[profile events] rows=%d", block.Rows()) - var ( - events []ProfileEvent - names = block.ColumnsNames() - ) - for r := 0; r < block.Rows(); r++ { - var event ProfileEvent - for i, b := range block.Columns { - switch names[i] { - case "host_name": - if err := b.ScanRow(&event.Hostname, r); err != nil { - return nil, err - } - case "current_time": - if err := b.ScanRow(&event.CurrentTime, r); err != nil { - return nil, err - } - case "thread_id": - if err := b.ScanRow(&event.ThreadID, r); err != nil { - return nil, err - } - case "type": - if err := b.ScanRow(&event.Type, r); err != nil { - return nil, err - } - case "name": - if err := b.ScanRow(&event.Name, r); err != nil { - return nil, err - } - case "value": - switch b.ScanType().Kind() { - case reflect.Uint64: - var v uint64 - if err := b.ScanRow(&v, r); err != nil { - return nil, err - } - event.Value = int64(v) - default: - if err := b.ScanRow(&event.Value, r); err != nil { - return nil, err - } - } - } - } - events = append(events, event) - } - return events, nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_query.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_query.go deleted file mode 100644 index 821444b21d..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_query.go +++ /dev/null @@ -1,93 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -func (c *connect) query(ctx context.Context, release func(*connect, error), query string, args ...interface{}) (*rows, error) { - var ( - options = queryOptions(ctx) - onProcess = options.onProcess() - body, err = bind(c.server.Timezone, query, args...) - ) - - if err != nil { - release(c, err) - return nil, err - } - - if deadline, ok := ctx.Deadline(); ok { - c.conn.SetDeadline(deadline) - defer c.conn.SetDeadline(time.Time{}) - } - - if err = c.sendQuery(body, &options); err != nil { - release(c, err) - return nil, err - } - - init, err := c.firstBlock(ctx, onProcess) - - if err != nil { - release(c, err) - return nil, err - } - - var ( - errors = make(chan error) - stream = make(chan *proto.Block, 2) - ) - - go func() { - onProcess.data = func(b *proto.Block) { - stream <- b - } - err := c.process(ctx, onProcess) - if err != nil { - errors <- err - } - close(stream) - close(errors) - release(c, err) - }() - - return &rows{ - block: init, - stream: stream, - errors: errors, - columns: init.ColumnsNames(), - structMap: c.structMap, - }, nil -} - -func (c *connect) queryRow(ctx context.Context, release func(*connect, error), query string, args ...interface{}) *row { - rows, err := c.query(ctx, release, query, args...) - if err != nil { - return &row{ - err: err, - } - } - return &row{ - rows: rows, - } -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_send_query.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_send_query.go deleted file mode 100644 index 867dd8dd92..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/conn_send_query.go +++ /dev/null @@ -1,52 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -// Connection::sendQuery -// https://github.com/ClickHouse/ClickHouse/blob/master/src/Client/Connection.cpp -func (c *connect) sendQuery(body string, o *QueryOptions) error { - c.debugf("[send query] compression=%t %s", c.compression, body) - if err := c.encoder.Byte(proto.ClientQuery); err != nil { - return err - } - q := proto.Query{ - ID: o.queryID, - Body: body, - Span: o.span, - QuotaKey: o.quotaKey, - Compression: c.compression, - InitialAddress: c.conn.LocalAddr().String(), - Settings: c.settings(o.settings), - } - if err := q.Encode(c.encoder, c.revision); err != nil { - return err - } - for _, table := range o.external { - if err := c.sendData(table.Block(), table.Name()); err != nil { - return err - } - } - if err := c.sendData(&proto.Block{}, ""); err != nil { - return err - } - return c.encoder.Flush() -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/context.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/context.go deleted file mode 100644 index b20f8be159..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/context.go +++ /dev/null @@ -1,175 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/ext" - "go.opentelemetry.io/otel/trace" -) - -var _contextOptionKey = &QueryOptions{ - settings: Settings{ - "_contextOption": struct{}{}, - }, -} - -type Settings map[string]interface{} -type ( - QueryOption func(*QueryOptions) error - QueryOptions struct { - span trace.SpanContext - async struct { - ok bool - wait bool - } - queryID string - quotaKey string - events struct { - logs func(*Log) - progress func(*Progress) - profileInfo func(*ProfileInfo) - profileEvents func([]ProfileEvent) - } - settings Settings - external []*ext.Table - } -) - -func WithSpan(span trace.SpanContext) QueryOption { - return func(o *QueryOptions) error { - o.span = span - return nil - } -} - -func WithQueryID(queryID string) QueryOption { - return func(o *QueryOptions) error { - o.queryID = queryID - return nil - } -} - -func WithQuotaKey(quotaKey string) QueryOption { - return func(o *QueryOptions) error { - o.quotaKey = quotaKey - return nil - } -} - -func WithSettings(settings Settings) QueryOption { - return func(o *QueryOptions) error { - o.settings = settings - return nil - } -} - -func WithLogs(fn func(*Log)) QueryOption { - return func(o *QueryOptions) error { - o.events.logs = fn - return nil - } -} - -func WithProgress(fn func(*Progress)) QueryOption { - return func(o *QueryOptions) error { - o.events.progress = fn - return nil - } -} - -func WithProfileInfo(fn func(*ProfileInfo)) QueryOption { - return func(o *QueryOptions) error { - o.events.profileInfo = fn - return nil - } -} - -func WithProfileEvents(fn func([]ProfileEvent)) QueryOption { - return func(o *QueryOptions) error { - o.events.profileEvents = fn - return nil - } -} - -func WithExternalTable(t ...*ext.Table) QueryOption { - return func(o *QueryOptions) error { - o.external = append(o.external, t...) - return nil - } -} - -func WithStdAsync(wait bool) QueryOption { - return func(o *QueryOptions) error { - o.async.ok, o.async.wait = true, wait - return nil - } -} - -func Context(parent context.Context, options ...QueryOption) context.Context { - opt := QueryOptions{ - settings: make(Settings), - } - for _, f := range options { - f(&opt) - } - return context.WithValue(parent, _contextOptionKey, opt) -} - -func queryOptions(ctx context.Context) QueryOptions { - if o, ok := ctx.Value(_contextOptionKey).(QueryOptions); ok { - if deadline, ok := ctx.Deadline(); ok { - if sec := time.Until(deadline).Seconds(); sec > 1 { - o.settings["max_execution_time"] = int(sec + 5) - } - } - return o - } - return QueryOptions{ - settings: make(Settings), - } -} - -func (q *QueryOptions) onProcess() *onProcess { - return &onProcess{ - logs: func(logs []Log) { - if q.events.logs != nil { - for _, l := range logs { - q.events.logs(&l) - } - } - }, - progress: func(p *Progress) { - if q.events.progress != nil { - q.events.progress(p) - } - }, - profileInfo: func(p *ProfileInfo) { - if q.events.profileInfo != nil { - q.events.profileInfo(p) - } - }, - profileEvents: func(events []ProfileEvent) { - if q.events.profileEvents != nil { - q.events.profileEvents(events) - } - }, - } -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/contributors/contributors.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/contributors/contributors.go deleted file mode 100644 index 7fcbae29fc..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/contributors/contributors.go +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package contributors - -import ( - _ "embed" - "strings" -) - -//go:embed list -var source string - -var List []string = strings.Split(source, "\n") diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/contributors/list b/vendor/github.com/ClickHouse/clickhouse-go/v2/contributors/list deleted file mode 100644 index 34131a85bf..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/contributors/list +++ /dev/null @@ -1,86 +0,0 @@ -Abraham Adberstein -Aleksandr Petrukhin -Alex Bocharov -Alex Yang -Alexander Chumakov -Alexander Obukhov -Alexey Milovidov -Alexey Palazhchenko -Alvaro Tuso -Andrey Ustinov -Ashish Gaurav -Benjamin Rupp -Cem Sancak -Chao Wang -Chris Duncan -Dale McDiarmid -Damir Sayfutdinov -Dan Walters -Daniel Bershatsky -Danila Migalin -Danny.Dunn -Darío -Denis Krivak -Derek Perkins -Dmitry Markov -Dmitry Ponomarev -Dmitry Ponomarev -Egor.Gorlin -Eugene Formanenko -Evan Au -Ewan -Florian Lehner -Félix Mattrat -Geoff Genz -Ian McGraw -Ivan Blinkov -Ivan Ivanov -Jake Sylvestre -Jakub Chábek -James Hartig -Jan Was -Jeehoon Kim -John Troy -Jon Aquino -LI Tao -Maksim Sokolnikov -Marek Vavruša -Marek Vavruša -Mark Andrus Roberts -Michael Vigovsky -Nay Linn -Oleg Strokachuk -Richard Artoul -Robert Sköld -Robin Hahling -Ross Rothenstine -Sergei Sobolev -Sergey Melekhin -Taras Matsyk -Thibault Deutsch -Tsimafei Bredau -Vespertinus -Yury Korolev -Yury Yurochko -alex -anton troyanov -chengzhi -dmitry kuzmin -gaetan.rizio -hulb -ilker moral -jiyongwang -kshvakov -neverlee -nevseliev -pavel raskin -sundy-li <543950155@qq.com> -vahid sohrabloo -vasily.popov -vl4deee11 -vl4deee11 -vladislav doster -vvoronin -yuankun -zxc111 -李盼 diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/docker-compose.yml b/vendor/github.com/ClickHouse/clickhouse-go/v2/docker-compose.yml deleted file mode 100644 index de88bb3caf..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -version: '3.9' -services: - clickhouse: - networks: - - clickhouse - container_name: clickhouse - image: clickhouse/clickhouse-server - ports: - - 127.0.0.1:8123:8123 - - 127.0.0.1:9000:9000 - - 127.0.0.1:9009:9009 -networks: - clickhouse: null diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/ext/ext.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/ext/ext.go deleted file mode 100644 index 48836a8220..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/ext/ext.go +++ /dev/null @@ -1,59 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package ext - -import ( - "github.com/ClickHouse/clickhouse-go/v2/lib/column" - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -func NewTable(name string, columns ...func(t *Table) error) (*Table, error) { - table := &Table{ - name: name, - block: &proto.Block{}, - } - for _, column := range columns { - if err := column(table); err != nil { - return nil, err - } - } - return table, nil -} - -type Table struct { - name string - block *proto.Block -} - -func (tbl *Table) Name() string { - return tbl.name -} - -func (tbl *Table) Block() *proto.Block { - return tbl.block -} - -func (tbl *Table) Append(v ...interface{}) error { - return tbl.block.Append(v...) -} - -func Column(name string, ct column.Type) func(t *Table) error { - return func(tbl *Table) error { - return tbl.block.AddColumn(name, ct) - } -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/encoder.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/encoder.go deleted file mode 100644 index 1ebc45cafe..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/encoder.go +++ /dev/null @@ -1,146 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package binary - -import ( - "encoding/binary" - "io" - "math" -) - -func NewEncoder(w io.Writer) *Encoder { - return &Encoder{ - output: w, - } -} - -type Encoder struct { - output io.Writer - scratch [binary.MaxVarintLen64]byte -} - -func (enc *Encoder) Raw(b []byte) error { - if _, err := enc.output.Write(b); err != nil { - return err - } - return nil -} - -func (enc *Encoder) Bool(v bool) error { - if v { - return enc.UInt8(1) - } - return enc.UInt8(0) -} - -func (enc *Encoder) Byte(b byte) error { - return enc.UInt8(b) -} - -func (enc *Encoder) Int8(v int8) error { - return enc.UInt8(uint8(v)) -} - -func (enc *Encoder) Int16(v int16) error { - return enc.UInt16(uint16(v)) -} - -func (enc *Encoder) Int32(v int32) error { - return enc.UInt32(uint32(v)) -} - -func (enc *Encoder) Int64(v int64) error { - return enc.UInt64(uint64(v)) -} - -func (enc *Encoder) UInt8(v uint8) error { - enc.scratch[0] = v - if _, err := enc.output.Write(enc.scratch[:1]); err != nil { - return err - } - return nil -} - -func (enc *Encoder) UInt16(v uint16) error { - enc.scratch[0] = byte(v) - enc.scratch[1] = byte(v >> 8) - if _, err := enc.output.Write(enc.scratch[:2]); err != nil { - return err - } - return nil -} - -func (enc *Encoder) UInt32(v uint32) error { - enc.scratch[0] = byte(v) - enc.scratch[1] = byte(v >> 8) - enc.scratch[2] = byte(v >> 16) - enc.scratch[3] = byte(v >> 24) - if _, err := enc.output.Write(enc.scratch[:4]); err != nil { - return err - } - return nil -} - -func (enc *Encoder) UInt64(v uint64) error { - enc.scratch[0] = byte(v) - enc.scratch[1] = byte(v >> 8) - enc.scratch[2] = byte(v >> 16) - enc.scratch[3] = byte(v >> 24) - enc.scratch[4] = byte(v >> 32) - enc.scratch[5] = byte(v >> 40) - enc.scratch[6] = byte(v >> 48) - enc.scratch[7] = byte(v >> 56) - if _, err := enc.output.Write(enc.scratch[:8]); err != nil { - return err - } - return nil -} - -func (enc *Encoder) Float32(v float32) error { - return enc.UInt32(math.Float32bits(v)) -} - -func (enc *Encoder) Float64(v float64) error { - return enc.UInt64(math.Float64bits(v)) -} - -func (enc *Encoder) Uvarint(v uint64) error { - ln := binary.PutUvarint(enc.scratch[:binary.MaxVarintLen64], v) - if _, err := enc.output.Write(enc.scratch[0:ln]); err != nil { - return err - } - return nil -} - -func (enc *Encoder) Flush() error { - if w, ok := enc.output.(interface{ Flush() error }); ok { - return w.Flush() - } - return nil -} - -func (enc *Encoder) String(v string) error { - str := Str2Bytes(v) - if err := enc.Uvarint(uint64(len(str))); err != nil { - return err - } - if _, err := enc.output.Write(str); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string.go deleted file mode 100644 index f94ef28894..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string.go +++ /dev/null @@ -1,39 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package binary - -import ( - "reflect" - "unsafe" -) - -// Copied from https://github.com/m3db/m3/blob/master/src/x/unsafe/string.go#L62 - -func unsafeStr2Bytes(str string) []byte { - if len(str) == 0 { - return nil - } - var scratch []byte - { - slice := (*reflect.SliceHeader)(unsafe.Pointer(&scratch)) - slice.Len = len(str) - slice.Cap = len(str) - slice.Data = (*reflect.StringHeader)(unsafe.Pointer(&str)).Data - } - return scratch -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string_safe.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string_safe.go deleted file mode 100644 index 0008b25d9b..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string_safe.go +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !amd64 && !arm64 -// +build !amd64,!arm64 - -package binary - -func Str2Bytes(str string) []byte { - return []byte(str) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string_unsafe.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string_unsafe.go deleted file mode 100644 index 8a101d1c5b..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/binary/string_unsafe.go +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build amd64 || arm64 -// +build amd64 arm64 - -package binary - -func Str2Bytes(str string) []byte { - return unsafeStr2Bytes(str) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/city64.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/city64.go deleted file mode 100644 index 1dc1f8ec67..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/city64.go +++ /dev/null @@ -1,62 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cityhash102 - -import ( - "encoding/binary" - "hash" -) - -type City64 struct { - s []byte -} - -var _ hash.Hash64 = (*City64)(nil) -var _ hash.Hash = (*City64)(nil) - -func New64() hash.Hash64 { - return &City64{} -} - -func (this *City64) Sum(b []byte) []byte { - b2 := make([]byte, 8) - binary.BigEndian.PutUint64(b2, this.Sum64()) - b = append(b, b2...) - return b -} - -func (this *City64) Sum64() uint64 { - return CityHash64(this.s, uint32(len(this.s))) -} - -func (this *City64) Reset() { - this.s = this.s[0:0] -} - -func (this *City64) BlockSize() int { - return 1 -} - -func (this *City64) Write(s []byte) (n int, err error) { - this.s = append(this.s, s...) - return len(s), nil -} - -func (this *City64) Size() int { - return 8 -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/doc.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/doc.go deleted file mode 100644 index e60469097b..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102/doc.go +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -/** COPY from https://github.com/zentures/cityhash/ - -NOTE: The code is modified to be compatible with CityHash128 used in ClickHouse -*/ -package cityhash102 diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/array.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/array.go deleted file mode 100644 index 5358d96751..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/array.go +++ /dev/null @@ -1,434 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type offset struct { - values UInt64 - scanType reflect.Type -} - -type Array struct { - depth int - chType Type - values Interface - offsets []*offset - scanType reflect.Type - name string -} - -func (col *Array) Name() string { - return col.name -} - -func (col *Array) parse(t Type) (_ Interface, err error) { - col.chType = t - var typeStr = string(t) - -parse: - for { - switch { - case strings.HasPrefix(typeStr, "Array("): - col.depth++ - typeStr = strings.TrimPrefix(typeStr, "Array(") - typeStr = strings.TrimSuffix(typeStr, ")") - default: - break parse - } - } - if col.depth != 0 { - if col.values, err = Type(typeStr).Column(col.name); err != nil { - return nil, err - } - offsetScanTypes := make([]reflect.Type, 0, col.depth) - col.offsets, col.scanType = make([]*offset, 0, col.depth), col.values.ScanType() - for i := 0; i < col.depth; i++ { - col.scanType = reflect.SliceOf(col.scanType) - offsetScanTypes = append(offsetScanTypes, col.scanType) - } - for i := len(offsetScanTypes) - 1; i >= 0; i-- { - col.offsets = append(col.offsets, &offset{ - scanType: offsetScanTypes[i], - }) - } - return col, nil - } - return nil, &UnsupportedColumnTypeError{ - t: t, - } -} - -func (col *Array) Base() Interface { - return col.values -} - -func (col *Array) Type() Type { - return col.chType -} - -func (col *Array) ScanType() reflect.Type { - return col.scanType -} - -func (col *Array) Rows() int { - if len(col.offsets) != 0 { - return len(col.offsets[0].values.data) - } - return 0 -} - -func (col *Array) Row(i int, ptr bool) interface{} { - return col.make(uint64(i), 0).Interface() -} - -func (col *Array) ScanRow(dest interface{}, row int) error { - elem := reflect.Indirect(reflect.ValueOf(dest)) - if elem.Type() != col.scanType { - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: string(col.chType), - Hint: fmt.Sprintf("try using *%s", col.scanType), - } - } - { - elem.Set(col.make(uint64(row), 0)) - } - return nil -} - -func (col *Array) Append(v interface{}) (nulls []uint8, err error) { - value := reflect.Indirect(reflect.ValueOf(v)) - if value.Kind() != reflect.Slice { - return nil, &ColumnConverterError{ - Op: "Append", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - Hint: "value must be a slice", - } - } - for i := 0; i < value.Len(); i++ { - if err := col.AppendRow(value.Index(i)); err != nil { - return nil, err - } - } - return -} - -func (col *Array) AppendRow(v interface{}) error { - var elem reflect.Value - switch v := v.(type) { - case reflect.Value: - elem = reflect.Indirect(v) - default: - elem = reflect.Indirect(reflect.ValueOf(v)) - } - if !elem.IsValid() || elem.Type() != col.scanType { - from := fmt.Sprintf("%T", v) - if !elem.IsValid() { - from = fmt.Sprintf("%v", v) - } - return &ColumnConverterError{ - Op: "AppendRow", - To: string(col.chType), - From: from, - Hint: fmt.Sprintf("try using %s", col.scanType), - } - } - return col.append(elem, 0) -} - -func (col *Array) append(elem reflect.Value, level int) error { - if level < col.depth { - offset := uint64(elem.Len()) - if ln := len(col.offsets[level].values.data); ln != 0 { - offset += col.offsets[level].values.data[ln-1] - } - col.offsets[level].values.data = append(col.offsets[level].values.data, offset) - for i := 0; i < elem.Len(); i++ { - if err := col.append(elem.Index(i), level+1); err != nil { - return err - } - } - return nil - } - if elem.Kind() == reflect.Ptr && elem.IsNil() { - return col.values.AppendRow(nil) - } - return col.values.AppendRow(elem.Interface()) -} - -func (col *Array) Decode(decoder *binary.Decoder, rows int) error { - for _, offset := range col.offsets { - if err := offset.values.Decode(decoder, rows); err != nil { - return err - } - switch { - case len(offset.values.data) > 0: - rows = int(offset.values.data[len(offset.values.data)-1]) - default: - rows = 0 - } - } - return col.values.Decode(decoder, rows) -} - -func (col *Array) Encode(encoder *binary.Encoder) error { - for _, offset := range col.offsets { - if err := offset.values.Encode(encoder); err != nil { - return err - } - } - return col.values.Encode(encoder) -} - -func (col *Array) ReadStatePrefix(decoder *binary.Decoder) error { - if serialize, ok := col.values.(CustomSerialization); ok { - if err := serialize.ReadStatePrefix(decoder); err != nil { - return err - } - } - return nil -} - -func (col *Array) WriteStatePrefix(encoder *binary.Encoder) error { - if serialize, ok := col.values.(CustomSerialization); ok { - if err := serialize.WriteStatePrefix(encoder); err != nil { - return err - } - } - return nil -} - -func (col *Array) make(row uint64, level int) reflect.Value { - offset := col.offsets[level] - var ( - end = offset.values.data[row] - start = uint64(0) - ) - if row > 0 { - start = offset.values.data[row-1] - } - var ( - base = offset.scanType.Elem() - isPtr = base.Kind() == reflect.Ptr - slice = reflect.MakeSlice(offset.scanType, 0, int(end-start)) - ) - for i := start; i < end; i++ { - var value reflect.Value - switch { - case level == len(col.offsets)-1: - switch v := col.values.Row(int(i), isPtr); { - case v == nil: - value = reflect.Zero(base) - default: - value = reflect.ValueOf(v) - } - default: - value = col.make(i, level+1) - } - slice = reflect.Append(slice, value) - } - return slice -} - -func (col *Array) scanJSONSlice(sliceType reflect.Type, row int, level int) (reflect.Value, error) { - // We could try and set - if it exceeds just return immediately - offset := col.offsets[level] - var ( - end = offset.values.data[row] - start = uint64(0) - ) - if row > 0 { - start = offset.values.data[row-1] - } - var jsonSlice reflect.Value - switch sliceType.Kind() { - case reflect.Interface: - jsonSlice = reflect.ValueOf(make([]interface{}, 0, int(end-start))) - case reflect.Slice: - jsonSlice = reflect.MakeSlice(sliceType, 0, int(end-start)) - default: - return reflect.Value{}, &Error{ - ColumnType: fmt.Sprint(sliceType.Kind()), - Err: fmt.Errorf("column %s - needs a slice or interface{}", col.Name()), - } - } - - for i := start; i < end; i++ { - var value reflect.Value - var err error - switch { - case level == len(col.offsets)-1: - switch dcol := col.values.(type) { - case *Nested: - aCol := dcol.Interface.(*Array) - value, err = aCol.parseJSONSliceOfObjects(sliceType.Elem(), int(i)) - if err != nil { - return reflect.Value{}, err - } - case *Array: - value, err = dcol.scanJSONSlice(sliceType.Elem(), int(i), 0) - if err != nil { - return reflect.Value{}, err - } - default: - v := col.values.Row(int(i), false) - if sliceType.Kind() == reflect.Interface { - value = reflect.New(sliceType).Elem() - if err := setJSONFieldValue(value, reflect.ValueOf(v)); err != nil { - return reflect.Value{}, err - } - } else { - value = reflect.New(sliceType.Elem()).Elem() - if err := setJSONFieldValue(value, reflect.ValueOf(v)); err != nil { - return reflect.Value{}, err - } - } - } - default: - value, err = col.scanJSONSlice(sliceType.Elem(), int(i), level+1) - if err != nil { - return reflect.Value{}, err - } - } - jsonSlice = reflect.Append(jsonSlice, value) - } - return jsonSlice, nil -} - -func (col *Array) parseJSONSliceOfObjects(sliceType reflect.Type, row int) (reflect.Value, error) { - if sliceType.Kind() == reflect.Interface { - // catches interface{} - Note this swallows custom interfaces to which maps couldn't conform - subMap := make(map[string]interface{}) - return col.scanJSONSliceOfMaps(reflect.SliceOf(reflect.TypeOf(subMap)), row) - } else if sliceType.Kind() == reflect.Slice { - // make a slice of the right type - we need this to be a slice of a type capable of taking an object as nested - switch sliceType.Elem().Kind() { - case reflect.Struct: - return col.scanJSONSliceOfStructs(sliceType, row) - case reflect.Map: - return col.scanJSONSliceOfMaps(sliceType, row) - case reflect.Interface: - // catches []interface{} - Note this swallows custom interfaces to which maps couldn't conform - // might lead to fail - subMap := make(map[string]interface{}) - return col.scanJSONSliceOfMaps(reflect.SliceOf(reflect.TypeOf(subMap)), row) - default: - return reflect.Value{}, &Error{ - ColumnType: fmt.Sprint(sliceType.Elem().Kind()), - Err: fmt.Errorf("column %s - needs a slice of objects or an interface{}", col.Name()), - } - } - return reflect.Value{}, nil - } - return reflect.Value{}, &Error{ - ColumnType: fmt.Sprint(sliceType.Kind()), - Err: fmt.Errorf("column %s - needs a slice or interface{}", col.Name()), - } -} - -// the following 2 functions can probably be refactored - the share alot of common code for structs and maps -func (col *Array) scanJSONSliceOfMaps(sliceType reflect.Type, row int) (reflect.Value, error) { - if sliceType.Kind() != reflect.Slice { - return reflect.Value{}, &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%s", sliceType), - From: string(col.Type()), - } - } - tCol, ok := col.values.(*Tuple) - if !ok { - return reflect.Value{}, &Error{ - ColumnType: fmt.Sprint(col.values.Type()), - Err: fmt.Errorf("column %s - must be a tuple", col.Name()), - } - } - // Array(Tuple so depth 1 for JSON - offset := col.offsets[0] - var ( - end = offset.values.data[row] - start = uint64(0) - ) - if row > 0 { - start = offset.values.data[row-1] - } - if end-start > 0 { - jsonSlice := reflect.MakeSlice(sliceType, 0, int(end-start)) - for i := start; i < end; i++ { - sMap := reflect.MakeMap(sliceType.Elem()) - if err := tCol.scanJSONMap(sMap, int(i)); err != nil { - return reflect.Value{}, err - } - jsonSlice = reflect.Append(jsonSlice, sMap) - } - return jsonSlice, nil - } - return reflect.MakeSlice(sliceType, 0, 0), nil -} - -func (col *Array) scanJSONSliceOfStructs(sliceType reflect.Type, row int) (reflect.Value, error) { - if sliceType.Kind() != reflect.Slice { - return reflect.Value{}, &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%s", sliceType), - From: string(col.Type()), - } - } - tCol, ok := col.values.(*Tuple) - if !ok { - return reflect.Value{}, &Error{ - ColumnType: fmt.Sprint(col.values.Type()), - Err: fmt.Errorf("column %s - must be a tuple", col.Name()), - } - } - // Array(Tuple so depth 1 for JSON - offset := col.offsets[0] - var ( - end = offset.values.data[row] - start = uint64(0) - ) - if row > 0 { - start = offset.values.data[row-1] - } - if end-start > 0 { - // create a slice of the type from the jsonSlice - if this might be interface{} as its driven by the target datastructure - jsonSlice := reflect.MakeSlice(sliceType, 0, int(end-start)) - for i := start; i < end; i++ { - sStruct := reflect.New(sliceType.Elem()).Elem() - if err := tCol.scanJSONStruct(sStruct, int(i)); err != nil { - return reflect.Value{}, err - } - jsonSlice = reflect.Append(jsonSlice, sStruct) - } - return jsonSlice, nil - } - return reflect.MakeSlice(sliceType, 0, 0), nil -} - -var ( - _ Interface = (*Array)(nil) - _ CustomSerialization = (*Array)(nil) -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/bigint.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/bigint.go deleted file mode 100644 index efc1dd5c67..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/bigint.go +++ /dev/null @@ -1,184 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "math/big" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type BigInt struct { - size int - data []byte - chType Type - name string -} - -func (col *BigInt) Name() string { - return col.name -} - -func (col *BigInt) Type() Type { - return col.chType -} - -func (col *BigInt) ScanType() reflect.Type { - return scanTypeBigInt -} - -func (col *BigInt) Rows() int { - return len(col.data) / col.size -} - -func (col *BigInt) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return value - } - return *value -} - -func (col *BigInt) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *big.Int: - *d = *col.row(row) - case **big.Int: - *d = new(big.Int) - **d = *col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: string(col.chType), - } - } - return nil -} - -func (col *BigInt) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []big.Int: - nulls = make([]uint8, len(v)) - for _, v := range v { - col.append(&v) - } - case []*big.Int: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.append(v) - default: - col.data, nulls[i] = append(col.data, make([]byte, col.size)...), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *BigInt) AppendRow(v interface{}) error { - switch v := v.(type) { - case big.Int: - col.append(&v) - case *big.Int: - switch { - case v != nil: - col.append(v) - default: - col.data = append(col.data, make([]byte, col.size)...) - } - case nil: - col.data = append(col.data, make([]byte, col.size)...) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *BigInt) Decode(decoder *binary.Decoder, rows int) error { - col.data = make([]byte, rows*col.size) - return decoder.Raw(col.data) -} - -func (col *BigInt) Encode(encoder *binary.Encoder) error { - return encoder.Raw(col.data) -} - -func (col *BigInt) row(i int) *big.Int { - return rawToBigInt(col.data[i*col.size : (i+1)*col.size]) -} - -func (col *BigInt) append(v *big.Int) { - dest := make([]byte, col.size) - bigIntToRaw(dest, new(big.Int).Set(v)) - col.data = append(col.data, dest...) -} - -func bigIntToRaw(dest []byte, v *big.Int) { - var sign int - if v.Sign() < 0 { - v.Not(v).FillBytes(dest) - sign = -1 - } else { - v.FillBytes(dest) - } - endianSwap(dest, sign < 0) -} - -func rawToBigInt(v []byte) *big.Int { - // LittleEndian to BigEndian - endianSwap(v, false) - var lt = new(big.Int) - if len(v) > 0 && v[0]&0x80 != 0 { - // [0] ^ will +1 - for i := 0; i < len(v); i++ { - v[i] = ^v[i] - } - lt.SetBytes(v) - // neg ^ will -1 - lt.Not(lt) - } else { - lt.SetBytes(v) - } - return lt -} - -func endianSwap(src []byte, not bool) { - for i := 0; i < len(src)/2; i++ { - if not { - src[i], src[len(src)-i-1] = ^src[len(src)-i-1], ^src[i] - } else { - src[i], src[len(src)-i-1] = src[len(src)-i-1], src[i] - } - } -} - -var _ Interface = (*BigInt)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/bool.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/bool.go deleted file mode 100644 index 9b3ef93662..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/bool.go +++ /dev/null @@ -1,150 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Bool struct { - values UInt8 - name string -} - -func (col *Bool) Name() string { - return col.name -} - -func (col *Bool) Type() Type { - return "Bool" -} - -func (col *Bool) ScanType() reflect.Type { - return scanTypeBool -} - -func (col *Bool) Rows() int { - return len(col.values.data) -} - -func (col *Bool) Row(i int, ptr bool) interface{} { - val := col.row(i) - if ptr { - return &val - } - return val -} - -func (col *Bool) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *bool: - *d = col.row(row) - case **bool: - *d = new(bool) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Bool", - } - } - return nil -} - -func (col *Bool) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []bool: - in := make([]uint8, 0, len(v)) - for _, v := range v { - switch { - case v: - in = append(in, 1) - default: - in = append(in, 0) - } - } - col.values.data, nulls = append(col.values.data, in...), make([]uint8, len(v)) - case []*bool: - nulls = make([]uint8, len(v)) - in := make([]uint8, 0, len(v)) - for i, v := range v { - var value uint8 - switch { - case v != nil: - if *v { - value = 1 - } - default: - nulls[i] = 1 - } - in = append(in, value) - } - col.values.data = append(col.values.data, in...) - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Bool", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Bool) AppendRow(v interface{}) error { - var value bool - switch v := v.(type) { - case bool: - value = v - case *bool: - if v != nil { - value = *v - } - case nil: - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Bool", - From: fmt.Sprintf("%T", v), - } - } - switch { - case value: - col.values.data = append(col.values.data, 1) - default: - col.values.data = append(col.values.data, 0) - } - return nil -} - -func (col *Bool) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *Bool) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -func (col *Bool) row(i int) bool { - return col.values.data[i] == 1 -} - -var _ Interface = (*Bool)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column.go deleted file mode 100644 index 6994106dd6..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column.go +++ /dev/null @@ -1,86 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Type string - -func (t Type) params() string { - switch start, end := strings.Index(string(t), "("), strings.LastIndex(string(t), ")"); { - case len(t) == 0, start <= 0, end <= 0, end < start: - return "" - default: - return string(t[start+1 : end]) - } -} - -type Error struct { - ColumnType string - Err error -} - -func (e *Error) Error() string { - return fmt.Sprintf("%s: %s", e.ColumnType, e.Err) -} - -type ColumnConverterError struct { - Op string - Hint string - From, To string -} - -func (e *ColumnConverterError) Error() string { - var hint string - if len(e.Hint) != 0 { - hint += ". " + e.Hint - } - return fmt.Sprintf("clickhouse [%s]: converting %s to %s is unsupported%s", e.Op, e.From, e.To, hint) -} - -type UnsupportedColumnTypeError struct { - t Type -} - -func (e *UnsupportedColumnTypeError) Error() string { - return fmt.Sprintf("clickhouse: unsupported column type %q", e.t) -} - -type Interface interface { - Name() string - Type() Type - Rows() int - Row(i int, ptr bool) interface{} - ScanRow(dest interface{}, row int) error - Append(v interface{}) (nulls []uint8, err error) - AppendRow(v interface{}) error - Decode(decoder *binary.Decoder, rows int) error - Encode(*binary.Encoder) error - ScanType() reflect.Type -} - -type CustomSerialization interface { - ReadStatePrefix(*binary.Decoder) error - WriteStatePrefix(*binary.Encoder) error -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_gen.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_gen.go deleted file mode 100644 index f0447ddcee..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_gen.go +++ /dev/null @@ -1,1155 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -// Code generated by make codegen DO NOT EDIT. -// source: lib/column/codegen/column.tpl - -package column - -import ( - "fmt" - "github.com/google/uuid" - "github.com/paulmach/orb" - "github.com/shopspring/decimal" - "math/big" - "net" - "reflect" - "strings" - "time" -) - -func (t Type) Column(name string) (Interface, error) { - switch t { - case "Float32": - return &Float32{name: name}, nil - case "Float64": - return &Float64{name: name}, nil - case "Int8": - return &Int8{name: name}, nil - case "Int16": - return &Int16{name: name}, nil - case "Int32": - return &Int32{name: name}, nil - case "Int64": - return &Int64{name: name}, nil - case "UInt8": - return &UInt8{name: name}, nil - case "UInt16": - return &UInt16{name: name}, nil - case "UInt32": - return &UInt32{name: name}, nil - case "UInt64": - return &UInt64{name: name}, nil - case "Int128": - return &BigInt{ - size: 16, - chType: t, - name: name, - }, nil - case "UInt128": - return &BigInt{ - size: 16, - chType: t, - name: name, - }, nil - case "Int256": - return &BigInt{ - size: 32, - chType: t, - name: name, - }, nil - case "UInt256": - return &BigInt{ - size: 32, - chType: t, - name: name, - }, nil - case "IPv4": - return &IPv4{name: name}, nil - case "IPv6": - return &IPv6{name: name}, nil - case "Bool", "Boolean": - return &Bool{name: name}, nil - case "Date": - return &Date{name: name}, nil - case "Date32": - return &Date32{name: name}, nil - case "UUID": - return &UUID{name: name}, nil - case "Nothing": - return &Nothing{name: name}, nil - case "Ring": - v, err := (&Array{name: name}).parse("Array(Point)") - if err != nil { - return nil, err - } - set := v.(*Array) - set.chType = "Ring" - return &Ring{ - set: set, - name: name, - }, nil - case "Polygon": - v, err := (&Array{name: name}).parse("Array(Ring)") - if err != nil { - return nil, err - } - set := v.(*Array) - set.chType = "Polygon" - return &Polygon{ - set: set, - name: name, - }, nil - case "MultiPolygon": - v, err := (&Array{name: name}).parse("Array(Polygon)") - if err != nil { - return nil, err - } - set := v.(*Array) - set.chType = "MultiPolygon" - return &MultiPolygon{ - set: set, - name: name, - }, nil - case "Point": - return &Point{name: name}, nil - case "String": - return &String{name: name}, nil - case "Object('json')": - return &JSONObject{name: name, root: true}, nil - } - - switch strType := string(t); { - case strings.HasPrefix(string(t), "Map("): - return (&Map{name: name}).parse(t) - case strings.HasPrefix(string(t), "Tuple("): - return (&Tuple{name: name}).parse(t) - case strings.HasPrefix(string(t), "Decimal("): - return (&Decimal{name: name}).parse(t) - case strings.HasPrefix(strType, "Nested("): - return (&Nested{name: name}).parse(t) - case strings.HasPrefix(string(t), "Array("): - return (&Array{name: name}).parse(t) - case strings.HasPrefix(string(t), "Interval"): - return (&Interval{name: name}).parse(t) - case strings.HasPrefix(string(t), "Nullable"): - return (&Nullable{name: name}).parse(t) - case strings.HasPrefix(string(t), "FixedString"): - return (&FixedString{name: name}).parse(t) - case strings.HasPrefix(string(t), "LowCardinality"): - return (&LowCardinality{name: name}).parse(t) - case strings.HasPrefix(string(t), "SimpleAggregateFunction"): - return (&SimpleAggregateFunction{name: name}).parse(t) - case strings.HasPrefix(string(t), "Enum8") || strings.HasPrefix(string(t), "Enum16"): - return Enum(t, name) - case strings.HasPrefix(string(t), "DateTime64"): - return (&DateTime64{name: name}).parse(t) - case strings.HasPrefix(strType, "DateTime") && !strings.HasPrefix(strType, "DateTime64"): - return (&DateTime{name: name}).parse(t) - } - return nil, &UnsupportedColumnTypeError{ - t: t, - } -} - -type ( - Float32 struct { - data []float32 - name string - } - Float64 struct { - data []float64 - name string - } - Int8 struct { - data []int8 - name string - } - Int16 struct { - data []int16 - name string - } - Int32 struct { - data []int32 - name string - } - Int64 struct { - data []int64 - name string - } - UInt8 struct { - data []uint8 - name string - } - UInt16 struct { - data []uint16 - name string - } - UInt32 struct { - data []uint32 - name string - } - UInt64 struct { - data []uint64 - name string - } -) - -var ( - _ Interface = (*Float32)(nil) - _ Interface = (*Float64)(nil) - _ Interface = (*Int8)(nil) - _ Interface = (*Int16)(nil) - _ Interface = (*Int32)(nil) - _ Interface = (*Int64)(nil) - _ Interface = (*UInt8)(nil) - _ Interface = (*UInt16)(nil) - _ Interface = (*UInt32)(nil) - _ Interface = (*UInt64)(nil) -) - -var ( - scanTypeFloat32 = reflect.TypeOf(float32(0)) - scanTypeFloat64 = reflect.TypeOf(float64(0)) - scanTypeInt8 = reflect.TypeOf(int8(0)) - scanTypeInt16 = reflect.TypeOf(int16(0)) - scanTypeInt32 = reflect.TypeOf(int32(0)) - scanTypeInt64 = reflect.TypeOf(int64(0)) - scanTypeUInt8 = reflect.TypeOf(uint8(0)) - scanTypeUInt16 = reflect.TypeOf(uint16(0)) - scanTypeUInt32 = reflect.TypeOf(uint32(0)) - scanTypeUInt64 = reflect.TypeOf(uint64(0)) - scanTypeIP = reflect.TypeOf(net.IP{}) - scanTypeBool = reflect.TypeOf(true) - scanTypeByte = reflect.TypeOf([]byte{}) - scanTypeUUID = reflect.TypeOf(uuid.UUID{}) - scanTypeTime = reflect.TypeOf(time.Time{}) - scanTypeRing = reflect.TypeOf(orb.Ring{}) - scanTypePoint = reflect.TypeOf(orb.Point{}) - scanTypeSlice = reflect.TypeOf([]interface{}{}) - scanTypeBigInt = reflect.TypeOf(&big.Int{}) - scanTypeString = reflect.TypeOf("") - scanTypePolygon = reflect.TypeOf(orb.Polygon{}) - scanTypeDecimal = reflect.TypeOf(decimal.Decimal{}) - scanTypeMultiPolygon = reflect.TypeOf(orb.MultiPolygon{}) -) - -func (col *Float32) Name() string { - return col.name -} - -func (col *Float32) Type() Type { - return "Float32" -} - -func (col *Float32) ScanType() reflect.Type { - return scanTypeFloat32 -} - -func (col *Float32) Rows() int { - return len(col.data) -} - -func (col *Float32) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *float32: - *d = value.data[row] - case **float32: - *d = new(float32) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Float32", - Hint: fmt.Sprintf("try using *%s", scanTypeFloat32), - } - } - return nil -} - -func (col *Float32) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *Float32) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []float32: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*float32: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Float32", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Float32) AppendRow(v interface{}) error { - switch v := v.(type) { - case float32: - col.data = append(col.data, v) - case *float32: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Float32", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *Float64) Name() string { - return col.name -} - -func (col *Float64) Type() Type { - return "Float64" -} - -func (col *Float64) ScanType() reflect.Type { - return scanTypeFloat64 -} - -func (col *Float64) Rows() int { - return len(col.data) -} - -func (col *Float64) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *float64: - *d = value.data[row] - case **float64: - *d = new(float64) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Float64", - Hint: fmt.Sprintf("try using *%s", scanTypeFloat64), - } - } - return nil -} - -func (col *Float64) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *Float64) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []float64: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*float64: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Float64", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Float64) AppendRow(v interface{}) error { - switch v := v.(type) { - case float64: - col.data = append(col.data, v) - case *float64: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Float64", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *Int8) Name() string { - return col.name -} - -func (col *Int8) Type() Type { - return "Int8" -} - -func (col *Int8) ScanType() reflect.Type { - return scanTypeInt8 -} - -func (col *Int8) Rows() int { - return len(col.data) -} - -func (col *Int8) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *int8: - *d = value.data[row] - case **int8: - *d = new(int8) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Int8", - Hint: fmt.Sprintf("try using *%s", scanTypeInt8), - } - } - return nil -} - -func (col *Int8) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *Int8) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []int8: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*int8: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Int8", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Int8) AppendRow(v interface{}) error { - switch v := v.(type) { - case int8: - col.data = append(col.data, v) - case *int8: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Int8", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *Int16) Name() string { - return col.name -} - -func (col *Int16) Type() Type { - return "Int16" -} - -func (col *Int16) ScanType() reflect.Type { - return scanTypeInt16 -} - -func (col *Int16) Rows() int { - return len(col.data) -} - -func (col *Int16) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *int16: - *d = value.data[row] - case **int16: - *d = new(int16) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Int16", - Hint: fmt.Sprintf("try using *%s", scanTypeInt16), - } - } - return nil -} - -func (col *Int16) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *Int16) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []int16: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*int16: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Int16", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Int16) AppendRow(v interface{}) error { - switch v := v.(type) { - case int16: - col.data = append(col.data, v) - case *int16: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Int16", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *Int32) Name() string { - return col.name -} - -func (col *Int32) Type() Type { - return "Int32" -} - -func (col *Int32) ScanType() reflect.Type { - return scanTypeInt32 -} - -func (col *Int32) Rows() int { - return len(col.data) -} - -func (col *Int32) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *int32: - *d = value.data[row] - case **int32: - *d = new(int32) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Int32", - Hint: fmt.Sprintf("try using *%s", scanTypeInt32), - } - } - return nil -} - -func (col *Int32) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *Int32) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []int32: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*int32: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Int32", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Int32) AppendRow(v interface{}) error { - switch v := v.(type) { - case int32: - col.data = append(col.data, v) - case *int32: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Int32", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *Int64) Name() string { - return col.name -} - -func (col *Int64) Type() Type { - return "Int64" -} - -func (col *Int64) ScanType() reflect.Type { - return scanTypeInt64 -} - -func (col *Int64) Rows() int { - return len(col.data) -} - -func (col *Int64) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *int64: - *d = value.data[row] - case **int64: - *d = new(int64) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Int64", - Hint: fmt.Sprintf("try using *%s", scanTypeInt64), - } - } - return nil -} - -func (col *Int64) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *Int64) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []int64: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*int64: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Int64", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Int64) AppendRow(v interface{}) error { - switch v := v.(type) { - case int64: - col.data = append(col.data, v) - case *int64: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Int64", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *UInt8) Name() string { - return col.name -} - -func (col *UInt8) Type() Type { - return "UInt8" -} - -func (col *UInt8) ScanType() reflect.Type { - return scanTypeUInt8 -} - -func (col *UInt8) Rows() int { - return len(col.data) -} - -func (col *UInt8) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *uint8: - *d = value.data[row] - case **uint8: - *d = new(uint8) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "UInt8", - Hint: fmt.Sprintf("try using *%s", scanTypeUInt8), - } - } - return nil -} - -func (col *UInt8) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *UInt8) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []uint8: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*uint8: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "UInt8", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *UInt8) AppendRow(v interface{}) error { - switch v := v.(type) { - case uint8: - col.data = append(col.data, v) - case *uint8: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - case bool: - var t uint8 - if v { - t = 1 - } - col.data = append(col.data, t) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "UInt8", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *UInt16) Name() string { - return col.name -} - -func (col *UInt16) Type() Type { - return "UInt16" -} - -func (col *UInt16) ScanType() reflect.Type { - return scanTypeUInt16 -} - -func (col *UInt16) Rows() int { - return len(col.data) -} - -func (col *UInt16) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *uint16: - *d = value.data[row] - case **uint16: - *d = new(uint16) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "UInt16", - Hint: fmt.Sprintf("try using *%s", scanTypeUInt16), - } - } - return nil -} - -func (col *UInt16) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *UInt16) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []uint16: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*uint16: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "UInt16", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *UInt16) AppendRow(v interface{}) error { - switch v := v.(type) { - case uint16: - col.data = append(col.data, v) - case *uint16: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "UInt16", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *UInt32) Name() string { - return col.name -} - -func (col *UInt32) Type() Type { - return "UInt32" -} - -func (col *UInt32) ScanType() reflect.Type { - return scanTypeUInt32 -} - -func (col *UInt32) Rows() int { - return len(col.data) -} - -func (col *UInt32) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *uint32: - *d = value.data[row] - case **uint32: - *d = new(uint32) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "UInt32", - Hint: fmt.Sprintf("try using *%s", scanTypeUInt32), - } - } - return nil -} - -func (col *UInt32) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *UInt32) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []uint32: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*uint32: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "UInt32", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *UInt32) AppendRow(v interface{}) error { - switch v := v.(type) { - case uint32: - col.data = append(col.data, v) - case *uint32: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "UInt32", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *UInt64) Name() string { - return col.name -} - -func (col *UInt64) Type() Type { - return "UInt64" -} - -func (col *UInt64) ScanType() reflect.Type { - return scanTypeUInt64 -} - -func (col *UInt64) Rows() int { - return len(col.data) -} - -func (col *UInt64) ScanRow(dest interface{}, row int) error { - value := *col - switch d := dest.(type) { - case *uint64: - *d = value.data[row] - case **uint64: - *d = new(uint64) - **d = value.data[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "UInt64", - Hint: fmt.Sprintf("try using *%s", scanTypeUInt64), - } - } - return nil -} - -func (col *UInt64) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *UInt64) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []uint64: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*uint64: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "UInt64", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *UInt64) AppendRow(v interface{}) error { - switch v := v.(type) { - case uint64: - col.data = append(col.data, v) - case *uint64: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, 0) - } - case nil: - col.data = append(col.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "UInt64", - From: fmt.Sprintf("%T", v), - } - } - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_safe_gen.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_safe_gen.go deleted file mode 100644 index f5d9b7bc77..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_safe_gen.go +++ /dev/null @@ -1,228 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build !amd64 && !arm64 -// +build !amd64,!arm64 - -// Code generated by make codegen DO NOT EDIT. -// source: lib/column/codegen/column_safe.tpl - -package column - -import ( - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -func (col *Float32) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.Float32() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *Float32) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.Float32(v); err != nil { - return err - } - } - return nil -} - -func (col *Float64) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.Float64() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *Float64) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.Float64(v); err != nil { - return err - } - } - return nil -} - -func (col *Int8) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.Int8() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *Int8) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.Int8(v); err != nil { - return err - } - } - return nil -} - -func (col *Int16) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.Int16() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *Int16) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.Int16(v); err != nil { - return err - } - } - return nil -} - -func (col *Int32) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.Int32() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *Int32) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.Int32(v); err != nil { - return err - } - } - return nil -} - -func (col *Int64) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.Int64() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *Int64) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.Int64(v); err != nil { - return err - } - } - return nil -} - -func (col *UInt8) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.UInt8() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *UInt8) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.UInt8(v); err != nil { - return err - } - } - return nil -} - -func (col *UInt16) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.UInt16() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *UInt16) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.UInt16(v); err != nil { - return err - } - } - return nil -} - -func (col *UInt32) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.UInt32() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *UInt32) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.UInt32(v); err != nil { - return err - } - } - return nil -} - -func (col *UInt64) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.UInt64() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *UInt64) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.UInt64(v); err != nil { - return err - } - } - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_unsafe_gen.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_unsafe_gen.go deleted file mode 100644 index f77aa539f9..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/column_unsafe_gen.go +++ /dev/null @@ -1,410 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//go:build amd64 || arm64 -// +build amd64 arm64 - -// Code generated by make codegen DO NOT EDIT. -// source: lib/column/codegen/column_safe.tpl - -package column - -import ( - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "reflect" - "unsafe" -) - -func (col *Float32) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 32 / 8 - - col.data = append(col.data, make([]float32, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *Float32) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 32 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *Float64) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 64 / 8 - - col.data = append(col.data, make([]float64, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *Float64) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 64 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *Int8) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 8 / 8 - - col.data = append(col.data, make([]int8, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *Int8) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 8 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *Int16) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 16 / 8 - - col.data = append(col.data, make([]int16, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *Int16) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 16 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *Int32) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 32 / 8 - - col.data = append(col.data, make([]int32, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *Int32) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 32 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *Int64) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 64 / 8 - - col.data = append(col.data, make([]int64, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *Int64) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 64 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *UInt8) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 8 / 8 - - col.data = append(col.data, make([]uint8, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *UInt8) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 8 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *UInt16) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 16 / 8 - - col.data = append(col.data, make([]uint16, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *UInt16) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 16 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *UInt32) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 32 / 8 - - col.data = append(col.data, make([]uint32, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *UInt32) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 32 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} - -func (col *UInt64) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - const size = 64 / 8 - - col.data = append(col.data, make([]uint64, rows)...) - - var dst []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&dst)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - if err := decoder.Raw(dst); err != nil { - return err - } - return nil -} - -func (col *UInt64) Encode(encoder *binary.Encoder) error { - if len(col.data) == 0 { - return nil - } - const size = 64 / 8 - scratch := make([]byte, size*len(col.data)) - { - var src []byte - slice := (*reflect.SliceHeader)(unsafe.Pointer(&src)) - slice.Data = (*reflect.SliceHeader)(unsafe.Pointer(col)).Data - slice.Len = len(col.data) * size - slice.Cap = cap(col.data) * size - - copy(scratch, src) - } - return encoder.Raw(scratch) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date.go deleted file mode 100644 index 0232548887..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date.go +++ /dev/null @@ -1,152 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -var ( - minDate, _ = time.Parse("2006-01-02 15:04:05", "1970-01-01 00:00:00") - maxDate, _ = time.Parse("2006-01-02 15:04:05", "2106-01-01 00:00:00") -) - -type Date struct { - values Int16 - name string -} - -func (col *Date) Name() string { - return col.name -} - -func (col *Date) Type() Type { - return "Date" -} - -func (col *Date) ScanType() reflect.Type { - return scanTypeTime -} - -func (col *Date) Rows() int { - return len(col.values.data) -} - -func (col *Date) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *Date) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *time.Time: - *d = col.row(row) - case **time.Time: - *d = new(time.Time) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Date", - } - } - return nil -} - -func (col *Date) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []time.Time: - in := make([]int16, 0, len(v)) - for _, t := range v { - if err := dateOverflow(minDate, maxDate, t, "2006-01-02"); err != nil { - return nil, err - } - in = append(in, int16(t.Unix()/secInDay)) - } - col.values.data, nulls = append(col.values.data, in...), make([]uint8, len(v)) - case []*time.Time: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - if err := dateOverflow(minDate, maxDate, *v, "2006-01-02"); err != nil { - return nil, err - } - col.values.data = append(col.values.data, int16(v.Unix()/secInDay)) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Date", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Date) AppendRow(v interface{}) error { - var date int16 - switch v := v.(type) { - case time.Time: - if err := dateOverflow(minDate, maxDate, v, "2006-01-02"); err != nil { - return err - } - date = int16(v.Unix() / secInDay) - case *time.Time: - if v != nil { - if err := dateOverflow(minDate, maxDate, *v, "2006-01-02"); err != nil { - return err - } - date = int16(v.Unix() / secInDay) - } - case nil: - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Date", - From: fmt.Sprintf("%T", v), - } - } - col.values.data = append(col.values.data, date) - return nil -} - -func (col *Date) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *Date) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -func (col *Date) row(i int) time.Time { - return time.Unix(int64(col.values.data[i])*secInDay, 0).UTC() -} - -var _ Interface = (*Date)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date32.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date32.go deleted file mode 100644 index e5b6d7b9a1..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date32.go +++ /dev/null @@ -1,156 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -var ( - minDate32, _ = time.Parse("2006-01-02 15:04:05", "1925-01-01 00:00:00") - maxDate32, _ = time.Parse("2006-01-02 15:04:05", "2283-11-11 00:00:00") -) - -type Date32 struct { - values Int32 - name string -} - -func (col *Date32) Name() string { - return col.name -} - -func (col *Date32) Type() Type { - return "Date32" -} - -func (col *Date32) ScanType() reflect.Type { - return scanTypeTime -} - -func (col *Date32) Rows() int { - return len(col.values.data) -} - -func (col *Date32) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *Date32) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *time.Time: - *d = col.row(row) - case **time.Time: - *d = new(time.Time) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Date32", - } - } - return nil -} - -func (col *Date32) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []time.Time: - in := make([]int32, 0, len(v)) - for _, t := range v { - if err := dateOverflow(minDate32, maxDate32, t, "2006-01-02"); err != nil { - return nil, err - } - in = append(in, timeToInt32(t)) - } - col.values.data, nulls = append(col.values.data, in...), make([]uint8, len(v)) - case []*time.Time: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - if err := dateOverflow(minDate32, maxDate32, *v, "2006-01-02"); err != nil { - return nil, err - } - col.values.data = append(col.values.data, timeToInt32(*v)) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Date32", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Date32) AppendRow(v interface{}) error { - var date int32 - switch v := v.(type) { - case time.Time: - if err := dateOverflow(minDate32, maxDate32, v, "2006-01-02"); err != nil { - return err - } - date = timeToInt32(v) - case *time.Time: - if v != nil { - if err := dateOverflow(minDate32, maxDate32, *v, "2006-01-02"); err != nil { - return err - } - date = timeToInt32(*v) - } - case nil: - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Date32", - From: fmt.Sprintf("%T", v), - } - } - col.values.data = append(col.values.data, date) - return nil -} - -func (col *Date32) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *Date32) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -func (col *Date32) row(i int) time.Time { - return time.Unix((int64(col.values.data[i]) * secInDay), 0).UTC() -} - -func timeToInt32(t time.Time) int32 { - return int32(t.Unix() / secInDay) -} - -var _ Interface = (*Date32)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date_helpers.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date_helpers.go deleted file mode 100644 index 2e6691ec6d..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/date_helpers.go +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "time" -) - -const secInDay = 24 * 60 * 60 - -func dateOverflow(min, max, v time.Time, format string) error { - if v.Before(min) || v.After(max) { - return &DateOverflowError{ - Min: min, - Max: max, - Value: v, - Format: format, - } - } - return nil -} - -type DateOverflowError struct { - Min, Max time.Time - Value time.Time - Format string -} - -func (e *DateOverflowError) Error() string { - return fmt.Sprintf("clickhouse: dateTime overflow. must be between %s and %s", e.Min.Format(e.Format), e.Max.Format(e.Format)) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/datetime.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/datetime.go deleted file mode 100644 index 2f9f68520e..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/datetime.go +++ /dev/null @@ -1,171 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - "strings" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/ClickHouse/clickhouse-go/v2/lib/timezone" -) - -var ( - minDateTime, _ = time.Parse("2006-01-02 15:04:05", "1970-01-01 00:00:00") - maxDateTime, _ = time.Parse("2006-01-02 15:04:05", "2105-12-31 23:59:59") -) - -type DateTime struct { - chType Type - values UInt32 - timezone *time.Location - name string -} - -func (col *DateTime) Name() string { - return col.name -} - -func (col *DateTime) parse(t Type) (_ *DateTime, err error) { - if col.chType = t; col.chType == "DateTime" { - return col, nil - } - var name = strings.TrimSuffix(strings.TrimPrefix(string(t), "DateTime('"), "')") - if col.timezone, err = timezone.Load(name); err != nil { - return nil, err - } - return col, nil -} - -func (col *DateTime) Type() Type { - return col.chType -} - -func (col *DateTime) ScanType() reflect.Type { - return scanTypeTime -} - -func (col *DateTime) Rows() int { - return len(col.values.data) -} - -func (col *DateTime) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *DateTime) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *time.Time: - *d = col.row(row) - case **time.Time: - *d = new(time.Time) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "DateTime", - } - } - return nil -} - -func (col *DateTime) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []time.Time: - in := make([]uint32, 0, len(v)) - for _, t := range v { - if err := dateOverflow(minDateTime, maxDateTime, t, "2006-01-02 15:04:05"); err != nil { - return nil, err - } - in = append(in, uint32(t.Unix())) - } - col.values.data, nulls = append(col.values.data, in...), make([]uint8, len(v)) - case []*time.Time: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - if err := dateOverflow(minDateTime, maxDateTime, *v, "2006-01-02 15:04:05"); err != nil { - return nil, err - } - col.values.data = append(col.values.data, uint32(v.Unix())) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "DateTime", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *DateTime) AppendRow(v interface{}) error { - var datetime uint32 - switch v := v.(type) { - case time.Time: - if err := dateOverflow(minDateTime, maxDateTime, v, "2006-01-02 15:04:05"); err != nil { - return err - } - datetime = uint32(v.Unix()) - case *time.Time: - if v != nil { - if err := dateOverflow(minDateTime, maxDateTime, *v, "2006-01-02 15:04:05"); err != nil { - return err - } - datetime = uint32(v.Unix()) - } - case nil: - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "DateTime", - From: fmt.Sprintf("%T", v), - } - } - col.values.data = append(col.values.data, datetime) - return nil -} - -func (col *DateTime) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *DateTime) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -func (col *DateTime) row(i int) time.Time { - v := time.Unix(int64(col.values.data[i]), 0) - if col.timezone != nil { - v = v.In(col.timezone) - } - return v -} - -var _ Interface = (*DateTime)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/datetime64.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/datetime64.go deleted file mode 100644 index 519713e4bd..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/datetime64.go +++ /dev/null @@ -1,245 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "math" - "reflect" - "strconv" - "strings" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/ClickHouse/clickhouse-go/v2/lib/timezone" -) - -var ( - minDateTime64, _ = time.Parse("2006-01-02 15:04:05", "1925-01-01 00:00:00") - maxDateTime64, _ = time.Parse("2006-01-02 15:04:05", "2283-11-11 00:00:00") -) - -type DateTime64 struct { - chType Type - values Int64 - timezone *time.Location - precision int - name string -} - -func (col *DateTime64) Name() string { - return col.name -} - -func (col *DateTime64) parse(t Type) (_ Interface, err error) { - col.chType = t - switch params := strings.Split(t.params(), ","); len(params) { - case 2: - if col.precision, err = strconv.Atoi(params[0]); err != nil { - return nil, err - } - if col.timezone, err = timezone.Load(params[1][2 : len(params[1])-1]); err != nil { - return nil, err - } - case 1: - if col.precision, err = strconv.Atoi(params[0]); err != nil { - return nil, err - } - default: - return nil, &UnsupportedColumnTypeError{ - t: t, - } - } - return col, nil -} - -func (col *DateTime64) Type() Type { - return col.chType -} - -func (col *DateTime64) ScanType() reflect.Type { - return scanTypeTime -} - -func (col *DateTime64) Rows() int { - return len(col.values.data) -} - -func (col *DateTime64) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *DateTime64) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *time.Time: - *d = col.row(row) - case **time.Time: - *d = new(time.Time) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Datetime64", - } - } - return nil -} - -func (col *DateTime64) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []int64: - col.values.data, nulls = append(col.values.data, v...), make([]uint8, len(v)) - case []*int64: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.values.data = append(col.values.data, *v) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - case []time.Time: - in := make([]int64, 0, len(v)) - for _, t := range v { - if err := dateOverflow(minDateTime64, maxDateTime64, t, "2006-01-02 15:04:05"); err != nil { - return nil, err - } - in = append(in, col.timeToInt64(t)) - } - col.values.data, nulls = append(col.values.data, in...), make([]uint8, len(v)) - case []*time.Time: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - if err := dateOverflow(minDateTime64, maxDateTime64, *v, "2006-01-02 15:04:05"); err != nil { - return nil, err - } - col.values.data = append(col.values.data, col.timeToInt64(*v)) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - case []string: - in := make([]int64, 0, len(v)) - for _, t := range v { - value, err := col.parseString(t) - if err != nil { - return nil, err - } - in = append(in, value) - } - col.values.data, nulls = append(col.values.data, in...), make([]uint8, len(v)) - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Datetime64", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *DateTime64) AppendRow(v interface{}) error { - var datetime int64 - switch v := v.(type) { - case int64: - datetime = v - case *int64: - if v != nil { - datetime = *v - } - case time.Time: - if err := dateOverflow(minDateTime64, maxDateTime64, v, "2006-01-02 15:04:05"); err != nil { - return err - } - datetime = col.timeToInt64(v) - case *time.Time: - if v != nil { - if err := dateOverflow(minDateTime64, maxDateTime64, *v, "2006-01-02 15:04:05"); err != nil { - return err - } - datetime = col.timeToInt64(*v) - } - case string: - var err error - datetime, err = col.parseString(v) - if err != nil { - return err - } - case nil: - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Datetime64", - From: fmt.Sprintf("%T", v), - } - } - col.values.data = append(col.values.data, datetime) - return nil -} - -func (col *DateTime64) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *DateTime64) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -func (col *DateTime64) row(i int) time.Time { - var nano int64 - if col.precision < 19 { - nano = col.values.data[i] * int64(math.Pow10(9-col.precision)) - } - var ( - sec = nano / int64(10e8) - nsec = nano - sec*10e8 - time = time.Unix(sec, nsec) - ) - if col.timezone != nil { - time = time.In(col.timezone) - } - return time -} - -func (col *DateTime64) timeToInt64(t time.Time) int64 { - var timestamp int64 - if !t.IsZero() { - timestamp = t.UnixNano() - } - return timestamp / int64(math.Pow10(9-col.precision)) -} - -func (col *DateTime64) parseString(value string) (int64, error) { - tv, err := time.Parse("2006-01-02 15:04:05.999", value) - if err != nil { - return 0, err - } - // scale to the appropriate units based on the precision - val := tv.UnixMilli() * int64(math.Pow10(col.precision-3)) - return val, nil -} - -var _ Interface = (*DateTime64)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/decimal.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/decimal.go deleted file mode 100644 index 6ee0d388f0..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/decimal.go +++ /dev/null @@ -1,254 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "errors" - "fmt" - "math/big" - "reflect" - "strconv" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/shopspring/decimal" -) - -type Decimal struct { - chType Type - scale int - nobits int // its domain is {32, 64, 128, 256} - precision int - values []decimal.Decimal - name string -} - -func (col *Decimal) Name() string { - return col.name -} - -func (col *Decimal) parse(t Type) (_ *Decimal, err error) { - col.chType = t - params := strings.Split(t.params(), ",") - if len(params) != 2 { - return nil, fmt.Errorf("invalid Decimal format: '%s'", t) - } - params[0] = strings.TrimSpace(params[0]) - params[1] = strings.TrimSpace(params[1]) - - if col.precision, err = strconv.Atoi(params[0]); err != nil { - return nil, fmt.Errorf("'%s' is not Decimal type: %s", t, err) - } else if col.precision < 1 { - return nil, errors.New("wrong precision of Decimal type") - } - - if col.scale, err = strconv.Atoi(params[1]); err != nil { - return nil, fmt.Errorf("'%s' is not Decimal type: %s", t, err) - } else if col.scale < 0 || col.scale > col.precision { - return nil, errors.New("wrong scale of Decimal type") - } - switch { - case col.precision <= 9: - col.nobits = 32 - case col.precision <= 18: - col.nobits = 64 - case col.precision <= 38: - col.nobits = 128 - default: - col.nobits = 256 - } - return col, nil -} - -func (col *Decimal) Type() Type { - return col.chType -} - -func (col *Decimal) ScanType() reflect.Type { - return scanTypeDecimal -} - -func (col *Decimal) Rows() int { - return len(col.values) -} - -func (col *Decimal) Row(i int, ptr bool) interface{} { - value := col.values[i] - if ptr { - return &value - } - return value -} - -func (col *Decimal) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *decimal.Decimal: - *d = col.values[row] - case **decimal.Decimal: - *d = new(decimal.Decimal) - **d = col.values[row] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Decimal", - } - } - return nil -} - -func (col *Decimal) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []decimal.Decimal: - col.values, nulls = append(col.values, v...), make([]uint8, len(v)) - case []*decimal.Decimal: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.values = append(col.values, *v) - default: - col.values, nulls[i] = append(col.values, decimal.New(0, 0)), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Decimal) AppendRow(v interface{}) error { - value := decimal.New(0, 0) - switch v := v.(type) { - case decimal.Decimal: - value = v - case *decimal.Decimal: - if v != nil { - value = *v - } - case nil: - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } - } - col.values = append(col.values, value) - return nil -} - -func (col *Decimal) Decode(decoder *binary.Decoder, rows int) error { - switch col.nobits { - case 32: - var base Int32 - if err := base.Decode(decoder, rows); err != nil { - return err - } - for _, v := range base.data { - col.values = append(col.values, decimal.New(int64(v), int32(-col.scale))) - } - case 64: - var base Int64 - if err := base.Decode(decoder, rows); err != nil { - return err - } - for _, v := range base.data { - col.values = append(col.values, decimal.New(int64(v), int32(-col.scale))) - } - case 128, 256: - var ( - size = col.nobits / 8 - scratch = make([]byte, rows*size) - ) - if err := decoder.Raw(scratch); err != nil { - return err - } - for i := 0; i < rows; i++ { - col.values = append(col.values, decimal.NewFromBigInt( - rawToBigInt(scratch[i*size:(i+1)*size]), - int32(-col.scale), - )) - } - default: - return fmt.Errorf("unsupported %s", col.chType) - } - return nil -} - -func (col *Decimal) Encode(encoder *binary.Encoder) error { - switch col.nobits { - case 32: - var base UInt32 - for _, v := range col.values { - var part uint32 - switch { - case v.Exponent() != int32(col.scale): - part = uint32(decimal.NewFromBigInt(v.Coefficient(), v.Exponent()+int32(col.scale)).IntPart()) - default: - part = uint32(v.IntPart()) - } - base.data = append(base.data, part) - } - return base.Encode(encoder) - case 64: - var base UInt64 - for _, v := range col.values { - var part uint64 - switch { - case v.Exponent() != int32(col.scale): - part = uint64(decimal.NewFromBigInt(v.Coefficient(), v.Exponent()+int32(col.scale)).IntPart()) - default: - part = uint64(v.IntPart()) - } - base.data = append(base.data, part) - } - return base.Encode(encoder) - case 128, 256: - var ( - size = col.nobits / 8 - scratch = make([]byte, col.Rows()*size) - ) - for i, v := range col.values { - var bi *big.Int - switch { - case v.Exponent() != int32(col.scale): - bi = decimal.NewFromBigInt(v.Coefficient(), v.Exponent()+int32(col.scale)).BigInt() - default: - bi = v.BigInt() - } - bigIntToRaw(scratch[i*size:(i+1)*size], bi) - } - return encoder.Raw(scratch) - } - return fmt.Errorf("unsupported %s", col.chType) -} - -func (col *Decimal) Scale() int64 { - return int64(col.scale) -} - -func (col *Decimal) Precision() int64 { - return int64(col.precision) -} - -var _ Interface = (*Decimal)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum.go deleted file mode 100644 index 33517d011c..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum.go +++ /dev/null @@ -1,104 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "errors" - "math" - "strconv" - "strings" -) - -func Enum(chType Type, name string) (Interface, error) { - var ( - payload string - columnType = string(chType) - ) - if len(columnType) < 8 { - return nil, &Error{ - ColumnType: string(chType), - Err: errors.New("invalid Enum"), - } - } - switch { - case strings.HasPrefix(columnType, "Enum8"): - payload = columnType[6:] - case strings.HasPrefix(columnType, "Enum16"): - payload = columnType[7:] - default: - return nil, &Error{ - ColumnType: string(chType), - Err: errors.New("invalid Enum"), - } - } - var ( - idents []string - indexes []int64 - ) - for _, block := range strings.Split(payload[:len(payload)-1], ",") { - parts := strings.Split(block, "=") - if len(parts) != 2 { - return nil, &Error{ - ColumnType: string(chType), - Err: errors.New("invalid Enum"), - } - } - var ( - ident = strings.TrimSpace(parts[0]) - index, err = strconv.ParseInt(strings.TrimSpace(parts[1]), 10, 16) - ) - if err != nil || len(ident) < 2 { - return nil, &Error{ - ColumnType: string(chType), - Err: errors.New("invalid Enum"), - } - } - ident = ident[1 : len(ident)-1] - idents, indexes = append(idents, ident), append(indexes, index) - } - if strings.HasPrefix(columnType, "Enum8") { - enum := Enum8{ - iv: make(map[string]uint8, len(idents)), - vi: make(map[uint8]string, len(idents)), - chType: chType, - name: name, - } - for i := range idents { - if indexes[i] > math.MaxUint8 { - return nil, &Error{ - ColumnType: string(chType), - Err: errors.New("invalid Enum"), - } - } - enum.iv[idents[i]] = uint8(indexes[i]) - enum.vi[uint8(indexes[i])] = idents[i] - } - return &enum, nil - } - enum := Enum16{ - iv: make(map[string]uint16, len(idents)), - vi: make(map[uint16]string, len(idents)), - chType: chType, - name: name, - } - for i := range idents { - enum.iv[idents[i]] = uint16(indexes[i]) - enum.vi[uint16(indexes[i])] = idents[i] - } - return &enum, nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum16.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum16.go deleted file mode 100644 index ef7a735619..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum16.go +++ /dev/null @@ -1,156 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Enum16 struct { - iv map[string]uint16 - vi map[uint16]string - chType Type - values UInt16 - name string -} - -func (col *Enum16) Name() string { - return col.name -} - -func (col *Enum16) Type() Type { - return col.chType -} - -func (col *Enum16) ScanType() reflect.Type { - return scanTypeString -} - -func (col *Enum16) Rows() int { - return len(col.values.data) -} - -func (col *Enum16) Row(i int, ptr bool) interface{} { - value := col.vi[col.values.data[i]] - if ptr { - return &value - } - return value -} - -func (col *Enum16) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *string: - *d = col.vi[col.values.data[row]] - case **string: - *d = new(string) - **d = col.vi[col.values.data[row]] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Enum16", - } - } - return nil -} - -func (col *Enum16) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []string: - nulls = make([]uint8, len(v)) - for _, elem := range v { - v, ok := col.iv[elem] - if !ok { - return nil, &Error{ - Err: fmt.Errorf("unknown element %q", elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - } - case []*string: - nulls = make([]uint8, len(v)) - for i, elem := range v { - switch { - case elem != nil: - v, ok := col.iv[*elem] - if !ok { - return nil, &Error{ - Err: fmt.Errorf("unknown element %q", *elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - } - return -} - -func (col *Enum16) AppendRow(elem interface{}) error { - switch elem := elem.(type) { - case string: - v, ok := col.iv[elem] - if !ok { - return &Error{ - Err: fmt.Errorf("unknown element %q", elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - case *string: - switch { - case elem != nil: - v, ok := col.iv[*elem] - if !ok { - return &Error{ - Err: fmt.Errorf("unknown element %q", *elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - default: - col.values.data = append(col.values.data, 0) - } - case nil: - col.values.data = append(col.values.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Enum16", - From: fmt.Sprintf("%T", elem), - } - } - return nil -} - -func (col *Enum16) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *Enum16) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -var _ Interface = (*Enum16)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum8.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum8.go deleted file mode 100644 index 89762d9a2a..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/enum8.go +++ /dev/null @@ -1,162 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Enum8 struct { - iv map[string]uint8 - vi map[uint8]string - chType Type - values UInt8 - name string -} - -func (col *Enum8) Name() string { - return col.name -} - -func (col *Enum8) Type() Type { - return col.chType -} - -func (col *Enum8) ScanType() reflect.Type { - return scanTypeString -} - -func (col *Enum8) Rows() int { - return len(col.values.data) -} - -func (col *Enum8) Row(i int, ptr bool) interface{} { - value := col.vi[col.values.data[i]] - if ptr { - return &value - } - return value -} - -func (col *Enum8) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *string: - *d = col.vi[col.values.data[row]] - case **string: - *d = new(string) - **d = col.vi[col.values.data[row]] - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Enum8", - } - } - return nil -} - -func (col *Enum8) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []string: - nulls = make([]uint8, len(v)) - for _, elem := range v { - v, ok := col.iv[elem] - if !ok { - return nil, &Error{ - Err: fmt.Errorf("unknown element %q", elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - } - case []*string: - nulls = make([]uint8, len(v)) - for i, elem := range v { - switch { - case elem != nil: - v, ok := col.iv[*elem] - if !ok { - return nil, &Error{ - Err: fmt.Errorf("unknown element %q", *elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - default: - col.values.data, nulls[i] = append(col.values.data, 0), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Enum8", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *Enum8) AppendRow(elem interface{}) error { - switch elem := elem.(type) { - case string: - v, ok := col.iv[elem] - if !ok { - return &Error{ - Err: fmt.Errorf("unknown element %q", elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - case *string: - switch { - case elem != nil: - v, ok := col.iv[*elem] - if !ok { - return &Error{ - Err: fmt.Errorf("unknown element %q", *elem), - ColumnType: string(col.chType), - } - } - col.values.data = append(col.values.data, v) - default: - col.values.data = append(col.values.data, 0) - } - case nil: - col.values.data = append(col.values.data, 0) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Enum8", - From: fmt.Sprintf("%T", elem), - } - } - return nil -} - -func (col *Enum8) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (col *Enum8) Encode(encoder *binary.Encoder) error { - return col.values.Encode(encoder) -} - -var _ Interface = (*Enum8)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/fixed_string.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/fixed_string.go deleted file mode 100644 index ca96152a03..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/fixed_string.go +++ /dev/null @@ -1,183 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "encoding" - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type FixedString struct { - data []byte - size int - name string -} - -func (col *FixedString) Name() string { - return col.name -} - -func (col *FixedString) parse(t Type) (*FixedString, error) { - if _, err := fmt.Sscanf(string(t), "FixedString(%d)", &col.size); err != nil { - return nil, err - } - return col, nil -} - -func (col *FixedString) Type() Type { - return Type(fmt.Sprintf("FixedString(%d)", col.size)) -} - -func (col *FixedString) ScanType() reflect.Type { - return scanTypeString -} - -func (col *FixedString) Rows() int { - if col.size == 0 { - return 0 - } - return len(col.data) / col.size -} - -func (col *FixedString) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *FixedString) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *string: - *d = col.row(row) - case **string: - *d = new(string) - **d = col.row(row) - case encoding.BinaryUnmarshaler: - return d.UnmarshalBinary(col.rowBytes(row)) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "FixedString", - } - } - return nil -} - -func (col *FixedString) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []string: - for _, v := range v { - if v == "" { - col.data = append(col.data, make([]byte, col.size)...) - } else { - col.data = append(col.data, binary.Str2Bytes(v)...) - } - } - nulls = make([]uint8, len(v)) - case []*string: - nulls = make([]uint8, len(v)) - for i, v := range v { - if v == nil { - nulls[i] = 1 - } - switch { - case v == nil: - col.data = append(col.data, make([]byte, col.size)...) - default: - if *v == "" { - col.data = append(col.data, make([]byte, col.size)...) - } else { - col.data = append(col.data, binary.Str2Bytes(*v)...) - } - } - } - case encoding.BinaryMarshaler: - data, err := v.MarshalBinary() - if err != nil { - return nil, err - } - col.data, nulls = append(col.data, data...), make([]uint8, len(data)/col.size) - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "FixedString", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *FixedString) AppendRow(v interface{}) (err error) { - data := make([]byte, col.size) - switch v := v.(type) { - case string: - if v != "" { - data = binary.Str2Bytes(v) - } - case *string: - if v != nil { - if *v != "" { - data = binary.Str2Bytes(*v) - } - } - case nil: - case encoding.BinaryMarshaler: - if data, err = v.MarshalBinary(); err != nil { - return err - } - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "FixedString", - From: fmt.Sprintf("%T", v), - } - } - col.data = append(col.data, data...) - return nil -} - -func (col *FixedString) Decode(decoder *binary.Decoder, rows int) error { - col.data = make([]byte, col.size*rows) - return decoder.Raw(col.data) -} - -func (col *FixedString) Encode(encoder *binary.Encoder) error { - if len(col.data)%col.size != 0 { - return &Error{ - ColumnType: string(col.Type()), - Err: fmt.Errorf("invalid column size. must be a multiple of %d bytes got %d bytes", col.size, len(col.data)), - } - } - return encoder.Raw(col.data) -} - -func (col *FixedString) row(i int) string { - return string(col.data[i*col.size : (i+1)*col.size]) -} - -func (col *FixedString) rowBytes(i int) []byte { - return col.data[i*col.size : (i+1)*col.size] -} - -var _ Interface = (*FixedString)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_multi_polygon.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_multi_polygon.go deleted file mode 100644 index c23270470c..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_multi_polygon.go +++ /dev/null @@ -1,122 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/paulmach/orb" -) - -type MultiPolygon struct { - set *Array - name string -} - -func (col *MultiPolygon) Name() string { - return col.name -} - -func (col *MultiPolygon) Type() Type { - return "MultiPolygon" -} - -func (col *MultiPolygon) ScanType() reflect.Type { - return scanTypeMultiPolygon -} - -func (col *MultiPolygon) Rows() int { - return col.set.Rows() -} - -func (col *MultiPolygon) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *MultiPolygon) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *orb.MultiPolygon: - *d = col.row(row) - case **orb.MultiPolygon: - *d = new(orb.MultiPolygon) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "MultiPolygon", - Hint: fmt.Sprintf("try using *%s", col.ScanType()), - } - } - return nil -} - -func (col *MultiPolygon) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []orb.MultiPolygon: - values := make([][]orb.Polygon, 0, len(v)) - for _, v := range v { - values = append(values, v) - } - return col.set.Append(values) - - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "MultiPolygon", - From: fmt.Sprintf("%T", v), - } - } -} - -func (col *MultiPolygon) AppendRow(v interface{}) error { - switch v := v.(type) { - case orb.MultiPolygon: - return col.set.AppendRow([]orb.Polygon(v)) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "MultiPolygon", - From: fmt.Sprintf("%T", v), - } - } -} - -func (col *MultiPolygon) Decode(decoder *binary.Decoder, rows int) error { - return col.set.Decode(decoder, rows) -} - -func (col *MultiPolygon) Encode(encoder *binary.Encoder) error { - return col.set.Encode(encoder) -} - -func (col *MultiPolygon) row(i int) orb.MultiPolygon { - var value []orb.Polygon - { - col.set.ScanRow(&value, i) - } - return value -} - -var _ Interface = (*MultiPolygon)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_point.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_point.go deleted file mode 100644 index 7fdc44352f..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_point.go +++ /dev/null @@ -1,132 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/paulmach/orb" -) - -type Point struct { - lon Float64 - lat Float64 - name string -} - -func (col *Point) Name() string { - return col.name -} - -func (col *Point) Type() Type { - return "Point" -} - -func (col *Point) ScanType() reflect.Type { - return scanTypePoint -} - -func (col *Point) Rows() int { - return col.lon.Rows() -} - -func (col *Point) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *Point) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *orb.Point: - *d = col.row(row) - case **orb.Point: - *d = new(orb.Point) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Point", - Hint: fmt.Sprintf("try using *%s", col.ScanType()), - } - } - return nil -} - -func (col *Point) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []orb.Point: - nulls = make([]uint8, len(v)) - for _, v := range v { - col.lon.data = append(col.lon.data, v.Lon()) - col.lat.data = append(col.lat.data, v.Lat()) - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Point", - From: fmt.Sprintf("%T", v), - } - } - return -} -func (col *Point) AppendRow(v interface{}) error { - switch v := v.(type) { - case orb.Point: - col.lon.data = append(col.lon.data, v.Lon()) - col.lat.data = append(col.lat.data, v.Lat()) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Point", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *Point) Decode(decoder *binary.Decoder, rows int) error { - if err := col.lon.Decode(decoder, rows); err != nil { - return err - } - if err := col.lat.Decode(decoder, rows); err != nil { - return err - } - return nil -} - -func (col *Point) Encode(encoder *binary.Encoder) error { - if err := col.lon.Encode(encoder); err != nil { - return err - } - return col.lat.Encode(encoder) -} - -func (col *Point) row(i int) orb.Point { - return orb.Point{ - col.lon.data[i], - col.lat.data[i], - } -} - -var _ Interface = (*Point)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_polygon.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_polygon.go deleted file mode 100644 index 96fd42a2c6..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_polygon.go +++ /dev/null @@ -1,122 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/paulmach/orb" -) - -type Polygon struct { - set *Array - name string -} - -func (col *Polygon) Name() string { - return col.name -} - -func (col *Polygon) Type() Type { - return "Polygon" -} - -func (col *Polygon) ScanType() reflect.Type { - return scanTypePolygon -} - -func (col *Polygon) Rows() int { - return col.set.Rows() -} - -func (col *Polygon) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *Polygon) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *orb.Polygon: - *d = col.row(row) - case **orb.Polygon: - *d = new(orb.Polygon) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Polygon", - Hint: fmt.Sprintf("try using *%s", col.ScanType()), - } - } - return nil -} - -func (col *Polygon) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []orb.Polygon: - values := make([][]orb.Ring, 0, len(v)) - for _, v := range v { - values = append(values, v) - } - return col.set.Append(values) - - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Polygon", - From: fmt.Sprintf("%T", v), - } - } -} - -func (col *Polygon) AppendRow(v interface{}) error { - switch v := v.(type) { - case orb.Polygon: - return col.set.AppendRow([]orb.Ring(v)) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Polygon", - From: fmt.Sprintf("%T", v), - } - } -} - -func (col *Polygon) Decode(decoder *binary.Decoder, rows int) error { - return col.set.Decode(decoder, rows) -} - -func (col *Polygon) Encode(encoder *binary.Encoder) error { - return col.set.Encode(encoder) -} - -func (col *Polygon) row(i int) orb.Polygon { - var value []orb.Ring - { - col.set.ScanRow(&value, i) - } - return value -} - -var _ Interface = (*Polygon)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_ring.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_ring.go deleted file mode 100644 index 99e080483f..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/geo_ring.go +++ /dev/null @@ -1,122 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/paulmach/orb" -) - -type Ring struct { - set *Array - name string -} - -func (col *Ring) Name() string { - return col.name -} - -func (col *Ring) Type() Type { - return "Ring" -} - -func (col *Ring) ScanType() reflect.Type { - return scanTypeRing -} - -func (col *Ring) Rows() int { - return col.set.Rows() -} - -func (col *Ring) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *Ring) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *orb.Ring: - *d = col.row(row) - case **orb.Ring: - *d = new(orb.Ring) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Ring", - Hint: fmt.Sprintf("try using *%s", col.ScanType()), - } - } - return nil -} - -func (col *Ring) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []orb.Ring: - values := make([][]orb.Point, 0, len(v)) - for _, v := range v { - values = append(values, v) - } - return col.set.Append(values) - - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "Ring", - From: fmt.Sprintf("%T", v), - } - } -} - -func (col *Ring) AppendRow(v interface{}) error { - switch v := v.(type) { - case orb.Ring: - return col.set.AppendRow([]orb.Point(v)) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "Ring", - From: fmt.Sprintf("%T", v), - } - } -} - -func (col *Ring) Decode(decoder *binary.Decoder, rows int) error { - return col.set.Decode(decoder, rows) -} - -func (col *Ring) Encode(encoder *binary.Encoder) error { - return col.set.Encode(encoder) -} - -func (col *Ring) row(i int) orb.Ring { - var value []orb.Point - { - col.set.ScanRow(&value, i) - } - return value -} - -var _ Interface = (*Ring)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/interval.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/interval.go deleted file mode 100644 index cca95e6651..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/interval.go +++ /dev/null @@ -1,105 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "errors" - "fmt" - "reflect" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Interval struct { - chType Type - values Int64 - name string -} - -func (col *Interval) Name() string { - return col.name -} - -func (col *Interval) parse(t Type) (Interface, error) { - switch col.chType = t; col.chType { - case "IntervalSecond", "IntervalMinute", "IntervalHour", "IntervalDay", "IntervalWeek", "IntervalMonth", "IntervalYear": - return col, nil - } - return nil, &UnsupportedColumnTypeError{ - t: t, - } -} - -func (col *Interval) Type() Type { return col.chType } -func (col *Interval) ScanType() reflect.Type { return scanTypeString } -func (col *Interval) Rows() int { return len(col.values.data) } -func (col *Interval) Row(i int, ptr bool) interface{} { - return col.row(i) -} -func (col *Interval) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *string: - *d = col.row(row) - case **string: - *d = new(string) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "Interval", - } - } - return nil -} - -func (Interval) Append(interface{}) ([]uint8, error) { - return nil, &Error{ - ColumnType: "Interval", - Err: errors.New("data type values can't be stored in tables"), - } -} - -func (Interval) AppendRow(interface{}) error { - return &Error{ - ColumnType: "Interval", - Err: errors.New("data type values can't be stored in tables"), - } -} - -func (col *Interval) Decode(decoder *binary.Decoder, rows int) error { - return col.values.Decode(decoder, rows) -} - -func (Interval) Encode(*binary.Encoder) error { - return &Error{ - ColumnType: "Interval", - Err: errors.New("data type values can't be stored in tables"), - } -} - -func (col *Interval) row(i int) string { - v := fmt.Sprintf("%d %s", col.values.data[i], strings.TrimPrefix(string(col.chType), "Interval")) - if col.values.data[i] > 1 { - v += "s" - } - return v -} - -var _ Interface = (*Interval)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/ipv4.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/ipv4.go deleted file mode 100644 index 00cc92e147..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/ipv4.go +++ /dev/null @@ -1,171 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "net" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type IPv4 struct { - data []byte - name string -} - -func (col *IPv4) Name() string { - return col.name -} - -func (col *IPv4) Type() Type { - return "IPv4" -} - -func (col *IPv4) ScanType() reflect.Type { - return scanTypeIP -} - -func (col *IPv4) Rows() int { - return len(col.data) / net.IPv4len -} - -func (col *IPv4) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *IPv4) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *net.IP: - *d = col.row(row) - case **net.IP: - *d = new(net.IP) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "IPv4", - } - } - return nil -} - -func (col *IPv4) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []net.IP: - nulls = make([]uint8, len(v)) - for _, v := range v { - ip := v.To4() - if ip == nil { - return nil, &ColumnConverterError{ - Op: "Append", - To: "IPv4", - From: "IPv6", - Hint: "invalid IP version", - } - } - col.data = append(col.data, IPv4ToBytes(ip)...) - } - case []*net.IP: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - ip := v.To4() - if ip == nil { - return nil, &ColumnConverterError{ - Op: "Append", - To: "IPv4", - From: "IPv6", - Hint: "invalid IP version", - } - } - col.data = append(col.data, IPv4ToBytes(ip)...) - default: - col.data, nulls[i] = append(col.data, make([]byte, net.IPv4len)...), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "IPv4", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *IPv4) AppendRow(v interface{}) error { - var ip net.IP - switch v := v.(type) { - case net.IP: - ip = v - case *net.IP: - switch { - case v != nil: - ip = *v - default: - ip = make(net.IP, net.IPv4len) - } - case nil: - ip = make(net.IP, net.IPv4len) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "IPv4", - From: fmt.Sprintf("%T", v), - } - } - data := ip.To4() - if data == nil { - return &ColumnConverterError{ - Op: "AppendRow", - To: "IPv4", - From: "IPv6", - Hint: "invalid IP version", - } - } - col.data = append(col.data, IPv4ToBytes(data)...) - return nil -} - -func (col *IPv4) Decode(decoder *binary.Decoder, rows int) error { - col.data = make([]byte, net.IPv4len*rows) - return decoder.Raw(col.data) -} - -func (col *IPv4) Encode(encoder *binary.Encoder) error { - return encoder.Raw(col.data) -} - -func (col *IPv4) row(i int) net.IP { - src := col.data[i*net.IPv4len : (i+1)*net.IPv4len] - return net.IPv4(src[3], src[2], src[1], src[0]).To4() -} - -func IPv4ToBytes(ip net.IP) []byte { - return []byte{ip[3], ip[2], ip[1], ip[0]} -} - -var _ Interface = (*IPv4)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/ipv6.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/ipv6.go deleted file mode 100644 index d1d98e79bd..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/ipv6.go +++ /dev/null @@ -1,150 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "net" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type IPv6 struct { - data []byte - name string -} - -func (col *IPv6) Name() string { - return col.name -} - -func (col *IPv6) Type() Type { - return "IPv6" -} - -func (col *IPv6) ScanType() reflect.Type { - return scanTypeIP -} - -func (col *IPv6) Rows() int { - return len(col.data) / net.IPv6len -} - -func (col *IPv6) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *IPv6) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *net.IP: - *d = col.row(row) - case **net.IP: - *d = new(net.IP) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "IPv6", - } - } - return nil -} - -func (col *IPv6) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []net.IP: - nulls = make([]uint8, len(v)) - for _, v := range v { - if len(v) != net.IPv6len { - v = v.To16() - } - col.data = append(col.data, v[:]...) - } - case []*net.IP: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - //copy so we don't modify original value - tmp := *v - if len(tmp) != net.IPv6len { - tmp = tmp.To16() - } - col.data = append(col.data, tmp[:]...) - default: - col.data, nulls[i] = append(col.data, make([]byte, net.IPv6len)...), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "IPv6", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *IPv6) AppendRow(v interface{}) error { - var ip net.IP - switch v := v.(type) { - case net.IP: - ip = v - case *net.IP: - switch { - case v != nil: - ip = *v - default: - ip = make(net.IP, net.IPv6len) - } - case nil: - ip = make(net.IP, net.IPv6len) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "IPv6", - From: fmt.Sprintf("%T", v), - } - } - if len(ip) != net.IPv6len { - ip = ip.To16() - } - col.data = append(col.data, ip[:]...) - return nil -} - -func (col *IPv6) Decode(decoder *binary.Decoder, rows int) error { - col.data = make([]byte, net.IPv6len*rows) - return decoder.Raw(col.data) -} - -func (col *IPv6) Encode(encoder *binary.Encoder) error { - return encoder.Raw(col.data) -} - -func (col *IPv6) row(i int) net.IP { - return col.data[i*net.IPv6len : (i+1)*net.IPv6len] -} - -var _ Interface = (*IPv6)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/json.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/json.go deleted file mode 100644 index 519f977dde..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/json.go +++ /dev/null @@ -1,904 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "reflect" - "strings" -) - -// inverse mapping - go types to clickhouse types -var kindMappings = map[reflect.Kind]string{ - reflect.String: "String", - reflect.Int: "Int64", - reflect.Int8: "Int8", - reflect.Int16: "Int16", - reflect.Int32: "Int32", - reflect.Int64: "Int64", - reflect.Uint: "UInt64", - reflect.Uint8: "UInt8", - reflect.Uint16: "UInt16", - reflect.Uint32: "UInt32", - reflect.Uint64: "UInt64", - reflect.Float32: "Float32", - reflect.Float64: "Float64", - reflect.Bool: "Boolean", -} - -// complex types for which a mapping exists - currently we map to String but could enhance in the future for other types -var typeMappings = map[string]struct{}{ - // currently JSON doesn't support DateTime, Decimal or IP so mapped to String - "time.Time": struct{}{}, - "decimal.Decimal": struct{}{}, - "net.IP": struct{}{}, - "uuid.UUID": struct{}{}, -} - -type JSON interface { - Interface - appendEmptyValue() error -} - -type JSONParent interface { - upsertValue(name string, ct string) (*JSONValue, error) - upsertList(name string) (*JSONList, error) - upsertObject(name string) (*JSONObject, error) - insertEmptyColumn(name string) error - columnNames() []string - rows() int -} - -func parseType(name string, vType reflect.Type, values interface{}, isArray bool, jCol JSONParent, numEmpty int) error { - _, ok := typeMappings[vType.String()] - if !ok { - return &UnsupportedColumnTypeError{ - t: Type(vType.String()), - } - } - ct := "String" - if isArray { - ct = fmt.Sprintf("Array(%s)", ct) - } - col, err := jCol.upsertValue(name, ct) - if err != nil { - return err - } - col.origType = vType - - //pre pad with empty - e.g. for new values in maps - for i := 0; i < numEmpty; i++ { - if isArray { - // empty array for nil of the right type - err = col.AppendRow([]string{}) - } else { - // empty value of the type - err = col.AppendRow(fmt.Sprint(reflect.New(vType).Elem().Interface())) - } - if err != nil { - return err - } - } - if isArray { - iValues := reflect.ValueOf(values) - sValues := make([]string, iValues.Len(), iValues.Len()) - for i := 0; i < iValues.Len(); i++ { - sValues[i] = fmt.Sprint(iValues.Index(i).Interface()) - } - return col.AppendRow(sValues) - } - return col.AppendRow(fmt.Sprint(values)) -} - -func parsePrimitive(name string, kind reflect.Kind, values interface{}, isArray bool, jCol JSONParent, numEmpty int) error { - ct, ok := kindMappings[kind] - if !ok { - return &UnsupportedColumnTypeError{ - t: Type(fmt.Sprintf("%s - %s", kind, reflect.TypeOf(values).String())), - } - } - var err error - if isArray { - ct = fmt.Sprintf("Array(%s)", ct) - // if we have a []interface{} we will need to cast to the target column type - this will be based on the first - // values types. Inconsistent slices will fail. - values, err = convertSlice(values) - if err != nil { - return err - } - } - col, err := jCol.upsertValue(name, ct) - if err != nil { - return err - } - - //pre pad with empty - e.g. for new values in maps - for i := 0; i < numEmpty; i++ { - if isArray { - // empty array for nil of the right type - err = col.AppendRow(reflect.MakeSlice(reflect.TypeOf(values), 0, 0).Interface()) - } else { - err = col.AppendRow(nil) - } - if err != nil { - return err - } - } - - return col.AppendRow(values) -} - -// converts a []interface{} of primitives to a typed slice -// maybe this can be done with reflection but likely slower. investigate. -// this uses the first value to determine the type - subsequent values must currently be of the same type - we might cast later -// but wider driver doesn't support e.g. int to int64 -func convertSlice(values interface{}) (interface{}, error) { - rValues := reflect.ValueOf(values) - if rValues.Len() == 0 || rValues.Index(0).Kind() != reflect.Interface { - return values, nil - } - var fType reflect.Type - for i := 0; i < rValues.Len(); i++ { - elem := rValues.Index(i).Elem() - if elem.IsValid() { - fType = elem.Type() - break - } - } - if fType == nil { - return []interface{}{}, nil - } - typedSlice := reflect.MakeSlice(reflect.SliceOf(fType), 0, rValues.Len()) - for i := 0; i < rValues.Len(); i++ { - value := rValues.Index(i) - if value.IsNil() { - typedSlice = reflect.Append(typedSlice, reflect.Zero(fType)) - continue - } - if rValues.Index(i).Elem().Type() != fType { - return nil, &Error{ - ColumnType: fmt.Sprint(fType), - Err: fmt.Errorf("inconsistent slices are not supported - expected %s got %s", fType, rValues.Index(i).Elem().Type()), - } - } - typedSlice = reflect.Append(typedSlice, rValues.Index(i).Elem()) - } - return typedSlice.Interface(), nil -} - -func (jCol *JSONList) createNewOffsets(num int) { - for i := 0; i < num; i++ { - //single depth so can take 1st - if len(jCol.offsets[0].values.data) == 0 { - // first entry in the column - jCol.offsets[0].values.data = []uint64{0} - } else { - // entry for this object to see offset from last - offsets are cumulative - jCol.offsets[0].values.data = append(jCol.offsets[0].values.data, jCol.offsets[0].values.data[len(jCol.offsets[0].values.data)-1]) - } - } -} - -func getFieldName(field reflect.StructField) (string, bool) { - name := field.Name - jsonTag := field.Tag.Get("json") - if jsonTag == "" { - return name, false - } - // not a standard but we allow - to omit fields - if jsonTag == "-" { - return name, true - } - return jsonTag, false -} - -func parseSlice(name string, values interface{}, jCol JSONParent, preFill int) error { - fType := reflect.TypeOf(values).Elem() - sKind := fType.Kind() - rValues := reflect.ValueOf(values) - - if sKind == reflect.Interface { - //use the first element to determine if it is a complex or primitive map - after this we need consistent dimensions - if rValues.Len() == 0 { - return nil - } - var value reflect.Value - for i := 0; i < rValues.Len(); i++ { - value = rValues.Index(i).Elem() - if value.IsValid() { - break - } - } - if !value.IsValid() { - return nil - } - fType = value.Type() - sKind = value.Kind() - } - - if _, ok := typeMappings[fType.String()]; ok { - return parseType(name, fType, values, true, jCol, preFill) - } else if sKind == reflect.Struct || sKind == reflect.Map || sKind == reflect.Slice { - if rValues.Len() == 0 { - return nil - } - col, err := jCol.upsertList(name) - if err != nil { - return err - } - col.createNewOffsets(preFill + 1) - for i := 0; i < rValues.Len(); i++ { - // increment offset - col.offsets[0].values.data[len(col.offsets[0].values.data)-1] += 1 - value := rValues.Index(i) - sKind = value.Kind() - if sKind == reflect.Interface { - sKind = value.Elem().Kind() - } - switch sKind { - case reflect.Struct: - col.isNested = true - if err = iterateStruct(value, col, 0); err != nil { - return err - } - case reflect.Map: - col.isNested = true - if err = iterateMap(value, col, 0); err != nil { - return err - } - case reflect.Slice: - if err = parseSlice("", value.Interface(), col, 0); err != nil { - return err - } - default: - // only happens if slice has a primitive mixed with complex types in a []interface{} - return &Error{ - ColumnType: fmt.Sprint(sKind), - Err: fmt.Errorf("slices must be same dimension in column %s", col.Name()), - } - } - } - return nil - } - return parsePrimitive(name, sKind, values, true, jCol, preFill) -} - -func parseStruct(name string, structVal reflect.Value, jCol JSONParent, preFill int) error { - col, err := jCol.upsertObject(name) - if err != nil { - return err - } - return iterateStruct(structVal, col, preFill) -} - -func iterateStruct(structVal reflect.Value, col JSONParent, preFill int) error { - // structs generally have consistent field counts but we ignore nil values that are interface{} as we can't infer from - // these until they occur - so we might need to either backfill when to do occur or insert empty based on previous - if structVal.Kind() == reflect.Interface { - // can happen if passed from []interface{} - structVal = structVal.Elem() - } - - currentColumns := col.columnNames() - columnLookup := make(map[string]struct{}) - numRows := col.rows() - for _, name := range currentColumns { - columnLookup[name] = struct{}{} - } - addedColumns := make([]string, structVal.NumField(), structVal.NumField()) - newColumn := false - - for i := 0; i < structVal.NumField(); i++ { - fName, omit := getFieldName(structVal.Type().Field(i)) - if omit { - continue - } - field := structVal.Field(i) - if !field.CanInterface() { - // can't interface - likely not exported so ignore the field - continue - } - kind := field.Kind() - value := field.Interface() - fType := field.Type() - //resolve underlying kind - if kind == reflect.Interface { - if value == nil { - // ignore nil fields - continue - } - kind = reflect.TypeOf(value).Kind() - field = reflect.ValueOf(value) - fType = field.Type() - } - if _, ok := columnLookup[fName]; !ok && len(currentColumns) > 0 { - // new column - need to handle missing - preFill = numRows - newColumn = true - } - if _, ok := typeMappings[fType.String()]; ok { - if err := parseType(fName, fType, value, false, col, preFill); err != nil { - return err - } - } else { - switch kind { - case reflect.Slice: - if reflect.ValueOf(value).Len() == 0 { - continue - } - if err := parseSlice(fName, value, col, preFill); err != nil { - return err - } - case reflect.Struct: - if err := parseStruct(fName, field, col, preFill); err != nil { - return err - } - case reflect.Map: - if err := parseMap(fName, field, col, preFill); err != nil { - return err - } - default: - if err := parsePrimitive(fName, kind, value, false, col, preFill); err != nil { - return err - } - } - } - addedColumns[i] = fName - if newColumn { - // reset as otherwise prefill overflow to other fields. But don't reset if this prefill has come from - // a higher level - preFill = 0 - } - } - // handle missing - missingColumns := difference(currentColumns, addedColumns) - for _, name := range missingColumns { - if err := col.insertEmptyColumn(name); err != nil { - return err - } - } - return nil -} - -func parseMap(name string, mapVal reflect.Value, jCol JSONParent, preFill int) error { - if mapVal.Type().Key().Kind() != reflect.String { - return &Error{ - ColumnType: fmt.Sprint(mapVal.Type().Key().Kind()), - Err: fmt.Errorf("map keys must be string for column %s", name), - } - } - col, err := jCol.upsertObject(name) - if err != nil { - return err - } - return iterateMap(mapVal, col, preFill) -} - -func iterateMap(mapVal reflect.Value, col JSONParent, preFill int) error { - // maps can have inconsistent numbers of elements - we must ensure they are consistent in the encoding - // two inconsistent options - 1. new - map has new columns 2. massing - map has missing columns - // for (1) we need to update previous, for (2) we need to ensure we add a null entry - if mapVal.Kind() == reflect.Interface { - // can happen if passed from []interface{} - mapVal = mapVal.Elem() - } - - currentColumns := col.columnNames() - //gives us a fast lookup for large maps - columnLookup := make(map[string]struct{}) - numRows := col.rows() - // true if we need nil values - for _, name := range currentColumns { - columnLookup[name] = struct{}{} - } - addedColumns := make([]string, len(mapVal.MapKeys()), len(mapVal.MapKeys())) - newColumn := false - for i, key := range mapVal.MapKeys() { - name := key.Interface().(string) - if _, ok := columnLookup[name]; !ok && len(currentColumns) > 0 { - // new column - need to handle - preFill = numRows - newColumn = true - } - field := mapVal.MapIndex(key) - kind := field.Kind() - fType := field.Type() - - if kind == reflect.Interface { - if field.Interface() == nil { - // ignore nil fields - continue - } - kind = reflect.TypeOf(field.Interface()).Kind() - field = reflect.ValueOf(field.Interface()) - fType = field.Type() - } - if _, ok := typeMappings[fType.String()]; ok { - if err := parseType(name, fType, field.Interface(), false, col, preFill); err != nil { - return err - } - } else { - switch kind { - case reflect.Struct: - if err := parseStruct(name, field, col, preFill); err != nil { - return err - } - case reflect.Slice: - if err := parseSlice(name, field.Interface(), col, preFill); err != nil { - return err - } - case reflect.Map: - if err := parseMap(name, field, col, preFill); err != nil { - return err - } - default: - if err := parsePrimitive(name, kind, field.Interface(), false, col, preFill); err != nil { - return err - } - } - } - addedColumns[i] = name - if newColumn { - // reset as otherwise prefill overflow to other fields. But don't reset if this prefill has come from - // a higher level - preFill = 0 - } - } - // handle missing - missingColumns := difference(currentColumns, addedColumns) - for _, name := range missingColumns { - if err := col.insertEmptyColumn(name); err != nil { - return err - } - } - return nil -} - -func appendStructOrMap(jCol *JSONObject, data interface{}) error { - vData := reflect.ValueOf(data) - kind := vData.Kind() - if kind == reflect.Struct { - return iterateStruct(vData, jCol, 0) - } - if kind == reflect.Map { - if reflect.TypeOf(data).Key().Kind() != reflect.String { - return &Error{ - ColumnType: fmt.Sprint(reflect.TypeOf(data).Key().Kind()), - Err: fmt.Errorf("map keys must be string for column %s", jCol.Name()), - } - } - return iterateMap(vData, jCol, 0) - } - return &UnsupportedColumnTypeError{ - t: Type(fmt.Sprint(kind)), - } -} - -type JSONValue struct { - Interface - // represents the type e.g. uuid - these may have been mapped to a Column type support by JSON e.g. String - origType reflect.Type -} - -func (jCol *JSONValue) appendEmptyValue() error { - switch jCol.Interface.(type) { - case *Array: - if jCol.Rows() > 0 { - return jCol.AppendRow(reflect.MakeSlice(reflect.TypeOf(jCol.Row(0, false)), 0, 0).Interface()) - } - return &Error{ - ColumnType: "unknown", - Err: fmt.Errorf("can't add empty value to column %s - no entries to infer type", jCol.Name()), - } - default: - // can't just append nil here as we need a custom nil value for the type - if jCol.origType != nil { - return jCol.AppendRow(fmt.Sprint(reflect.New(jCol.origType).Elem().Interface())) - } - return jCol.AppendRow(nil) - } -} - -func (jCol *JSONValue) Type() Type { - return Type(fmt.Sprintf("%s %s", jCol.Name(), jCol.Interface.Type())) -} - -type JSONList struct { - Array - name string - isNested bool // indicates if this a list of objects i.e. a Nested -} - -func (jCol *JSONList) Name() string { - return jCol.name -} - -func (jCol *JSONList) columnNames() []string { - return jCol.Array.values.(*JSONObject).columnNames() -} - -func (jCol *JSONList) rows() int { - return jCol.values.(*JSONObject).Rows() -} - -func createJSONList(name string) (jCol *JSONList) { - // lists are represented as Nested which are in turn encoded as Array(Tuple()). We thus pass a Array(JSONObject()) - // as this encodes like a tuple - lCol := &JSONList{ - name: name, - } - lCol.values = &JSONObject{} - // depth should always be one as nested arrays aren't possible - lCol.depth = 1 - lCol.scanType = reflect.SliceOf(lCol.values.ScanType()) - offsetScanTypes := []reflect.Type{lCol.scanType} - lCol.offsets = []*offset{{ - scanType: offsetScanTypes[0], - }} - return lCol -} - -func (jCol *JSONList) appendEmptyValue() error { - // only need to bump the offsets - jCol.createNewOffsets(1) - return nil -} - -func (jCol *JSONList) insertEmptyColumn(name string) error { - return jCol.values.(*JSONObject).insertEmptyColumn(name) -} - -func (jCol *JSONList) upsertValue(name string, ct string) (*JSONValue, error) { - // check if column exists and reuse if same type, error if same name and different type - cols := jCol.values.(*JSONObject).columns - for i := range cols { - sCol := cols[i] - if sCol.Name() == name { - vCol, ok := cols[i].(*JSONValue) - if !ok { - sType := cols[i].Type() - return nil, &Error{ - ColumnType: fmt.Sprint(sType), - Err: fmt.Errorf("type mismatch in column %s - expected value, got %s", name, sType), - } - } - tType := vCol.Interface.Type() - if tType != Type(ct) { - return nil, &Error{ - ColumnType: ct, - Err: fmt.Errorf("type mismatch in column %s - expected %s, got %s", name, tType, ct), - } - } - return vCol, nil - } - } - col, err := Type(ct).Column(name) - if err != nil { - return nil, err - } - vCol := &JSONValue{ - Interface: col, - } - jCol.values.(*JSONObject).columns = append(cols, vCol) - return vCol, nil -} - -func (jCol *JSONList) upsertList(name string) (*JSONList, error) { - // check if column exists and reuse if same type, error if same name and different type - cols := jCol.values.(*JSONObject).columns - for i := range cols { - sCol := cols[i] - if sCol.Name() == name { - sCol, ok := cols[i].(*JSONList) - if !ok { - return nil, &Error{ - ColumnType: fmt.Sprint(cols[i].Type()), - Err: fmt.Errorf("type mismatch in column %s - expected list, got %s", name, cols[i].Type()), - } - } - return sCol, nil - } - } - lCol := createJSONList(name) - jCol.values.(*JSONObject).columns = append(cols, lCol) - return lCol, nil - -} - -func (jCol *JSONList) upsertObject(name string) (*JSONObject, error) { - // check if column exists and reuse if same type, error if same name and different type - cols := jCol.values.(*JSONObject).columns - for i := range cols { - sCol := cols[i] - if sCol.Name() == name { - sCol, ok := cols[i].(*JSONObject) - if !ok { - sType := cols[i].Type() - return nil, &Error{ - ColumnType: fmt.Sprint(sType), - Err: fmt.Errorf("type mismatch in column %s, expected object got %s", name, sType), - } - } - return sCol, nil - } - } - // lists are represented as Nested which are in turn encoded as Array(Tuple()). We thus pass a Array(JSONObject()) - // as this encodes like a tuple - oCol := &JSONObject{ - name: name, - } - jCol.values.(*JSONObject).columns = append(cols, oCol) - return oCol, nil -} - -func (jCol *JSONList) Type() Type { - cols := jCol.values.(*JSONObject).columns - subTypes := make([]string, len(cols)) - for i, v := range cols { - subTypes[i] = string(v.Type()) - } - // can be a list of lists or a nested - if jCol.isNested { - return Type(fmt.Sprintf("%s Nested(%s)", jCol.name, strings.Join(subTypes, ", "))) - } - return Type(fmt.Sprintf("%s Array(%s)", jCol.name, strings.Join(subTypes, ", "))) -} - -type JSONObject struct { - columns []JSON - name string - root bool - encoding uint8 -} - -func (jCol *JSONObject) Name() string { - return jCol.name -} - -func (jCol *JSONObject) columnNames() []string { - columns := make([]string, len(jCol.columns), len(jCol.columns)) - for i := range jCol.columns { - columns[i] = jCol.columns[i].Name() - } - return columns -} - -func (jCol *JSONObject) rows() int { - return jCol.Rows() -} - -func (jCol *JSONObject) appendEmptyValue() error { - for i := range jCol.columns { - if err := jCol.columns[i].appendEmptyValue(); err != nil { - return err - } - } - return nil -} - -func (jCol *JSONObject) insertEmptyColumn(name string) error { - for i := range jCol.columns { - if jCol.columns[i].Name() == name { - if err := jCol.columns[i].appendEmptyValue(); err != nil { - return err - } - return nil - } - } - return &Error{ - ColumnType: "unknown", - Err: fmt.Errorf("column %s is missing - empty value cannot be appended", name), - } -} - -func (jCol *JSONObject) upsertValue(name string, ct string) (*JSONValue, error) { - for i := range jCol.columns { - sCol := jCol.columns[i] - if sCol.Name() == name { - vCol, ok := jCol.columns[i].(*JSONValue) - if !ok { - sType := jCol.columns[i].Type() - return nil, &Error{ - ColumnType: fmt.Sprint(sType), - Err: fmt.Errorf("type mismatch in column %s, expected value got %s", name, sType), - } - } - if vCol.Interface.Type() != Type(ct) { - return nil, &Error{ - ColumnType: ct, - Err: fmt.Errorf("type mismatch in column %s, expected %s got %s", name, vCol.Interface.Type(), ct), - } - } - return vCol, nil - } - } - col, err := Type(ct).Column(name) - if err != nil { - return nil, err - } - vCol := &JSONValue{ - Interface: col, - } - jCol.columns = append(jCol.columns, vCol) - return vCol, nil -} - -func (jCol *JSONObject) upsertList(name string) (*JSONList, error) { - for i := range jCol.columns { - sCol := jCol.columns[i] - if sCol.Name() == name { - sCol, ok := jCol.columns[i].(*JSONList) - if !ok { - sType := jCol.columns[i].Type() - return nil, &Error{ - ColumnType: fmt.Sprint(sType), - Err: fmt.Errorf("type mismatch in column %s, expected list got %s", name, sType), - } - } - return sCol, nil - } - } - lCol := createJSONList(name) - jCol.columns = append(jCol.columns, lCol) - return lCol, nil -} - -func (jCol *JSONObject) upsertObject(name string) (*JSONObject, error) { - // check if it exists - for i := range jCol.columns { - sCol := jCol.columns[i] - if sCol.Name() == name { - sCol, ok := jCol.columns[i].(*JSONObject) - if !ok { - sType := jCol.columns[i].Type() - return nil, &Error{ - ColumnType: fmt.Sprint(sType), - Err: fmt.Errorf("type mismatch in column %s, expected object got %s", name, sType), - } - } - return sCol, nil - } - } - // not present so create - oCol := &JSONObject{ - name: name, - } - jCol.columns = append(jCol.columns, oCol) - return oCol, nil -} - -func (jCol *JSONObject) Type() Type { - if jCol.root { - return "Object('json')" - } - return jCol.FullType() -} - -func (jCol *JSONObject) FullType() Type { - subTypes := make([]string, len(jCol.columns)) - for i, v := range jCol.columns { - subTypes[i] = string(v.Type()) - } - if jCol.root { - return Type(fmt.Sprintf("Tuple(%s)", strings.Join(subTypes, ", "))) - } - return Type(fmt.Sprintf("%s Tuple(%s)", jCol.name, strings.Join(subTypes, ", "))) -} - -func (jCol *JSONObject) ScanType() reflect.Type { - return scanTypeSlice -} - -func (jCol *JSONObject) Rows() int { - if len(jCol.columns) != 0 { - return jCol.columns[0].Rows() - } - return 0 -} - -func (jCol *JSONObject) Row(i int, ptr bool) interface{} { - panic("Not implemented") -} - -func (jCol *JSONObject) ScanRow(dest interface{}, row int) error { - panic("Not implemented") -} - -func (jCol *JSONObject) Append(v interface{}) (nulls []uint8, err error) { - jSlice := reflect.ValueOf(v) - if jSlice.Kind() != reflect.Slice { - return nil, &ColumnConverterError{ - Op: "Append", - To: string(jCol.Type()), - From: fmt.Sprintf("slice of structs/map or strings required - received %T", v), - } - } - for i := 0; i < jSlice.Len(); i++ { - if err := jCol.AppendRow(jSlice.Index(i).Interface()); err != nil { - return nil, err - } - } - return nil, nil -} - -func (jCol *JSONObject) AppendRow(v interface{}) error { - if reflect.ValueOf(v).Kind() == reflect.Struct || reflect.ValueOf(v).Kind() == reflect.Map { - if jCol.columns != nil && jCol.encoding == 1 { - return &Error{ - ColumnType: fmt.Sprint(jCol.Type()), - Err: fmt.Errorf("encoding of JSON columns cannot be mixed in a batch - %s cannot be added as previously String", reflect.ValueOf(v).Kind()), - } - } - err := appendStructOrMap(jCol, v) - return err - } - switch v := v.(type) { - case string: - if jCol.columns != nil && jCol.encoding == 0 { - return &Error{ - ColumnType: fmt.Sprint(jCol.Type()), - Err: fmt.Errorf("encoding of JSON columns cannot be mixed in a batch - %s cannot be added as previously Struct/Map", reflect.ValueOf(v).Kind()), - } - } - jCol.encoding = 1 - if jCol.columns == nil { - jCol.columns = append(jCol.columns, &JSONValue{Interface: &String{}}) - } - jCol.columns[0].AppendRow(v) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "String", - From: fmt.Sprintf("json row must be struct, map or string - received %T", v), - } - } - return nil -} - -func (jCol *JSONObject) Decode(decoder *binary.Decoder, rows int) error { - panic("Not implemented") -} - -func (jCol *JSONObject) Encode(encoder *binary.Encoder) error { - if jCol.root && jCol.encoding == 0 { - if err := encoder.String(string(jCol.FullType())); err != nil { - return err - } - } - for _, c := range jCol.columns { - if err := c.Encode(encoder); err != nil { - return err - } - } - return nil -} - -func (jCol *JSONObject) ReadStatePrefix(decoder *binary.Decoder) error { - _, err := decoder.UInt8() - return err -} - -func (jCol *JSONObject) WriteStatePrefix(encoder *binary.Encoder) error { - return encoder.UInt8(jCol.encoding) -} - -var ( - _ Interface = (*JSONObject)(nil) - _ CustomSerialization = (*JSONObject)(nil) -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/lowcardinality.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/lowcardinality.go deleted file mode 100644 index 8c0fabd4a8..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/lowcardinality.go +++ /dev/null @@ -1,304 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "errors" - "fmt" - "math" - "reflect" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -const indexTypeMask = 0b11111111 - -const ( - keyUInt8 = 0 - keyUInt16 = 1 - keyUInt32 = 2 - keyUInt64 = 3 -) - -const ( - /// Need to read dictionary if it wasn't. - needGlobalDictionaryBit = 1 << 8 - /// Need to read additional keys. Additional keys are stored before indexes as value N and N keys after them. - hasAdditionalKeysBit = 1 << 9 - /// Need to update dictionary. It means that previous granule has different dictionary. - needUpdateDictionary = 1 << 10 - - updateAll = hasAdditionalKeysBit | needUpdateDictionary -) - -const sharedDictionariesWithAdditionalKeys = 1 - -// https://github.com/ClickHouse/ClickHouse/blob/master/src/Columns/ColumnLowCardinality.cpp -// https://github.com/ClickHouse/clickhouse-cpp/blob/master/clickhouse/columns/lowcardinality.cpp -type LowCardinality struct { - key byte - rows int - index Interface - chType Type - nullable bool - - keys8 UInt8 - keys16 UInt16 - keys32 UInt32 - keys64 UInt64 - - append struct { - keys []int - index map[interface{}]int - } - name string -} - -func (col *LowCardinality) Name() string { - return col.name -} - -func (col *LowCardinality) parse(t Type) (_ *LowCardinality, err error) { - col.chType = t - col.append.index = make(map[interface{}]int) - if col.index, err = Type(t.params()).Column(col.name); err != nil { - return nil, err - } - if nullable, ok := col.index.(*Nullable); ok { - col.nullable, nullable.enable = true, false - } - return col, nil -} - -func (col *LowCardinality) Type() Type { - return col.chType -} - -func (col *LowCardinality) ScanType() reflect.Type { - return col.index.ScanType() -} - -func (col *LowCardinality) Rows() int { - return col.rows -} - -func (col *LowCardinality) Row(i int, ptr bool) interface{} { - idx := col.indexRowNum(i) - if idx == 0 && col.nullable { - return nil - } - return col.index.Row(idx, ptr) -} - -func (col *LowCardinality) ScanRow(dest interface{}, row int) error { - idx := col.indexRowNum(row) - if idx == 0 && col.nullable { - return nil - } - return col.index.ScanRow(dest, idx) -} - -func (col *LowCardinality) Append(v interface{}) (nulls []uint8, err error) { - value := reflect.Indirect(reflect.ValueOf(v)) - if value.Kind() != reflect.Slice { - return nil, &ColumnConverterError{ - Op: "Append", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } - } - for i := 0; i < value.Len(); i++ { - if err := col.AppendRow(value.Index(i).Interface()); err != nil { - return nil, err - } - } - return -} - -func (col *LowCardinality) AppendRow(v interface{}) error { - col.rows++ - if col.index.Rows() == 0 { // init - if col.index.AppendRow(nil); col.nullable { - col.index.AppendRow(nil) - } - } - if v == nil { - col.append.keys = append(col.append.keys, 0) - return nil - } - switch x := v.(type) { - case time.Time: - v = x.Truncate(time.Second) - } - if _, found := col.append.index[v]; !found { - if err := col.index.AppendRow(v); err != nil { - return err - } - col.append.index[v] = col.index.Rows() - 1 - } - col.append.keys = append(col.append.keys, col.append.index[v]) - return nil -} - -func (col *LowCardinality) Decode(decoder *binary.Decoder, rows int) error { - if rows == 0 { - return nil - } - indexSerializationType, err := decoder.UInt64() - if err != nil { - return err - } - col.key = byte(indexSerializationType & indexTypeMask) - switch col.key { - case keyUInt8, keyUInt16, keyUInt32, keyUInt64: - default: - return &Error{ - ColumnType: "LowCardinality", - Err: errors.New("invalid index serialization version value"), - } - } - switch { - case indexSerializationType&needGlobalDictionaryBit == 1: - return &Error{ - ColumnType: "LowCardinality", - Err: errors.New("global dictionary is not supported"), - } - case indexSerializationType&hasAdditionalKeysBit == 0: - return &Error{ - ColumnType: "LowCardinality", - Err: errors.New("additional keys bit is missing"), - } - } - indexRows, err := decoder.Int64() - if err != nil { - return err - } - if err := col.index.Decode(decoder, int(indexRows)); err != nil { - return err - } - keysRows, err := decoder.Int64() - if err != nil { - return err - } - col.rows = int(keysRows) - return col.keys().Decode(decoder, col.rows) -} - -func (col *LowCardinality) Encode(encoder *binary.Encoder) error { - if col.rows == 0 { - return nil - } - defer func() { - col.append.keys, col.append.index = nil, nil - }() - ixLen := uint64(len(col.append.index)) - switch { - case ixLen < math.MaxUint8: - col.key = keyUInt8 - for _, v := range col.append.keys { - if err := col.keys8.AppendRow(uint8(v)); err != nil { - return err - } - } - case ixLen < math.MaxUint16: - col.key = keyUInt16 - for _, v := range col.append.keys { - if err := col.keys16.AppendRow(uint16(v)); err != nil { - return err - } - } - case ixLen < math.MaxUint32: - col.key = keyUInt32 - for _, v := range col.append.keys { - if err := col.keys32.AppendRow(uint32(v)); err != nil { - return err - } - } - default: - col.key = keyUInt64 - for _, v := range col.append.keys { - if err := col.keys64.AppendRow(uint64(v)); err != nil { - return err - } - } - } - if err := encoder.UInt64(updateAll | uint64(col.key)); err != nil { - return err - } - if err := encoder.Int64(int64(col.index.Rows())); err != nil { - return err - } - if err := col.index.Encode(encoder); err != nil { - return err - } - keys := col.keys() - if err := encoder.Int64(int64(keys.Rows())); err != nil { - return err - } - return keys.Encode(encoder) -} - -func (col *LowCardinality) ReadStatePrefix(decoder *binary.Decoder) error { - keyVersion, err := decoder.UInt64() - if err != nil { - return err - } - if keyVersion != sharedDictionariesWithAdditionalKeys { - return &Error{ - ColumnType: "LowCardinality", - Err: errors.New("invalid key serialization version value"), - } - } - return nil -} - -func (col *LowCardinality) WriteStatePrefix(encoder *binary.Encoder) error { - return encoder.UInt64(sharedDictionariesWithAdditionalKeys) -} - -func (col *LowCardinality) keys() Interface { - switch col.key { - case keyUInt8: - return &col.keys8 - case keyUInt16: - return &col.keys16 - case keyUInt32: - return &col.keys32 - } - return &col.keys64 -} - -func (col *LowCardinality) indexRowNum(row int) int { - switch v := col.keys().Row(row, false).(type) { - case uint8: - return int(v) - case uint16: - return int(v) - case uint32: - return int(v) - case uint64: - return int(v) - } - return 0 -} - -var ( - _ Interface = (*LowCardinality)(nil) - _ CustomSerialization = (*LowCardinality)(nil) -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/map.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/map.go deleted file mode 100644 index e019364db6..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/map.go +++ /dev/null @@ -1,216 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -// https://github.com/ClickHouse/ClickHouse/blob/master/src/Columns/ColumnMap.cpp -type Map struct { - keys Interface - values Interface - chType Type - offsets Int64 - scanType reflect.Type - name string -} - -func (col *Map) Name() string { - return col.name -} - -func (col *Map) parse(t Type) (_ Interface, err error) { - col.chType = t - if types := strings.SplitN(t.params(), ",", 2); len(types) == 2 { - if col.keys, err = Type(strings.TrimSpace(types[0])).Column(col.name); err != nil { - return nil, err - } - if col.values, err = Type(strings.TrimSpace(types[1])).Column(col.name); err != nil { - return nil, err - } - col.scanType = reflect.MapOf( - col.keys.ScanType(), - col.values.ScanType(), - ) - return col, nil - } - return nil, &UnsupportedColumnTypeError{ - t: t, - } -} - -func (col *Map) Type() Type { - return col.chType -} - -func (col *Map) ScanType() reflect.Type { - return col.scanType -} - -func (col *Map) Rows() int { - return len(col.offsets.data) -} - -func (col *Map) Row(i int, ptr bool) interface{} { - return col.row(i).Interface() -} - -func (col *Map) ScanRow(dest interface{}, i int) error { - value := reflect.Indirect(reflect.ValueOf(dest)) - if value.Type() != col.scanType { - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: string(col.chType), - Hint: fmt.Sprintf("try using %s", col.scanType), - } - } - { - value.Set(col.row(i)) - } - return nil -} - -func (col *Map) Append(v interface{}) (nulls []uint8, err error) { - value := reflect.Indirect(reflect.ValueOf(v)) - if value.Kind() != reflect.Slice { - return nil, &ColumnConverterError{ - Op: "Append", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - Hint: fmt.Sprintf("try using %s", col.scanType), - } - } - for i := 0; i < value.Len(); i++ { - if err := col.AppendRow(value.Index(i).Interface()); err != nil { - return nil, err - } - } - return -} - -func (col *Map) AppendRow(v interface{}) error { - value := reflect.Indirect(reflect.ValueOf(v)) - if value.Type() != col.scanType { - return &ColumnConverterError{ - Op: "AppendRow", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - Hint: fmt.Sprintf("try using %s", col.scanType), - } - } - var ( - size int64 - iter = value.MapRange() - ) - for iter.Next() { - size++ - if err := col.keys.AppendRow(iter.Key().Interface()); err != nil { - return err - } - if err := col.values.AppendRow(iter.Value().Interface()); err != nil { - return err - } - } - var prev int64 - if n := len(col.offsets.data); n != 0 { - prev = col.offsets.data[n-1] - } - col.offsets.data = append(col.offsets.data, prev+size) - return nil -} - -func (col *Map) Decode(decoder *binary.Decoder, rows int) error { - if err := col.offsets.Decode(decoder, rows); err != nil { - return err - } - size := int(col.offsets.data[len(col.offsets.data)-1]) - if err := col.keys.Decode(decoder, size); err != nil { - return err - } - return col.values.Decode(decoder, size) -} - -func (col *Map) Encode(encoder *binary.Encoder) error { - if err := col.offsets.Encode(encoder); err != nil { - return err - } - if err := col.keys.Encode(encoder); err != nil { - return err - } - return col.values.Encode(encoder) -} - -func (col *Map) ReadStatePrefix(decoder *binary.Decoder) error { - if serialize, ok := col.keys.(CustomSerialization); ok { - if err := serialize.ReadStatePrefix(decoder); err != nil { - return err - } - } - if serialize, ok := col.values.(CustomSerialization); ok { - if err := serialize.ReadStatePrefix(decoder); err != nil { - return err - } - } - return nil -} - -func (col *Map) WriteStatePrefix(encoder *binary.Encoder) error { - if serialize, ok := col.keys.(CustomSerialization); ok { - if err := serialize.WriteStatePrefix(encoder); err != nil { - return err - } - } - if serialize, ok := col.values.(CustomSerialization); ok { - if err := serialize.WriteStatePrefix(encoder); err != nil { - return err - } - } - return nil -} - -func (col *Map) row(n int) reflect.Value { - var ( - prev int64 - value = reflect.MakeMap(col.scanType) - ) - if n != 0 { - prev = col.offsets.data[n-1] - } - var ( - size = int(col.offsets.data[n] - prev) - from = int(prev) - ) - for next := 0; next < size; next++ { - value.SetMapIndex( - reflect.ValueOf(col.keys.Row(from+next, false)), - reflect.ValueOf(col.values.Row(from+next, false)), - ) - } - return value -} - -var ( - _ Interface = (*Map)(nil) - _ CustomSerialization = (*Map)(nil) -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nested.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nested.go deleted file mode 100644 index 6b9691acf1..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nested.go +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "strings" -) - -type Nested struct { - Interface - name string -} - -func asDDL(cols []namedCol) string { - sCols := make([]string, len(cols), len(cols)) - for i := range cols { - sCols[i] = fmt.Sprintf("%s %s", cols[i].name, cols[i].colType) - } - return strings.Join(sCols, ", ") -} - -func (col *Nested) parse(t Type) (_ Interface, err error) { - columns := fmt.Sprintf("Array(Tuple(%s))", asDDL(nestedColumns(t.params()))) - if col.Interface, err = (&Array{name: col.name}).parse(Type(columns)); err != nil { - return nil, err - } - return col, nil -} - -//Address Nested(City String, Devices Nested(Id String)), Friend Tuple(Id Int16), Id Int16, Name String -func nestedColumns(raw string) (columns []namedCol) { - var ( - nBegin int - begin int - brackets int - ) - for i, r := range raw + "," { - switch r { - case '(': - brackets++ - case ')': - brackets-- - case ' ': - if brackets == 0 { - begin = i + 1 - } - case ',': - if brackets == 0 { - columns, begin = append(columns, namedCol{ - name: strings.TrimSpace(raw[nBegin:begin]), - colType: Type(raw[begin:i]), - }), i+1 - nBegin = i + 1 - continue - } - } - } - for i, column := range columns { - if strings.HasPrefix(string(column.colType), "Nested(") { - columns[i] = namedCol{ - colType: Type(fmt.Sprintf("Array(Tuple(%s))", asDDL(nestedColumns(column.colType.params())))), - name: column.name, - } - } - } - return -} - -var _ Interface = (*Nested)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nothing.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nothing.go deleted file mode 100644 index 0dfb038779..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nothing.go +++ /dev/null @@ -1,66 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "errors" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Nothing struct { - name string -} - -func (n Nothing) Name() string { - return n.name -} - -func (Nothing) Type() Type { return "Nothing" } -func (Nothing) ScanType() reflect.Type { return reflect.TypeOf(nil) } -func (Nothing) Rows() int { return 0 } -func (Nothing) Row(int, bool) interface{} { return nil } -func (Nothing) ScanRow(interface{}, int) error { return nil } -func (Nothing) Append(interface{}) ([]uint8, error) { - return nil, &Error{ - ColumnType: "Nothing", - Err: errors.New("data type values can't be stored in tables"), - } -} -func (Nothing) AppendRow(interface{}) error { - return &Error{ - ColumnType: "Nothing", - Err: errors.New("data type values can't be stored in tables"), - } -} -func (Nothing) Decode(decoder *binary.Decoder, rows int) error { - scratch := make([]byte, rows) - if err := decoder.Raw(scratch); err != nil { - return err - } - return nil -} -func (Nothing) Encode(*binary.Encoder) error { - return &Error{ - ColumnType: "Nothing", - Err: errors.New("data type values can't be stored in tables"), - } -} - -var _ Interface = (*Nothing)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nullable.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nullable.go deleted file mode 100644 index 58aeae1787..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/nullable.go +++ /dev/null @@ -1,133 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Nullable struct { - base Interface - nulls UInt8 - enable bool - scanType reflect.Type - name string -} - -func (col *Nullable) Name() string { - return col.name -} - -func (col *Nullable) parse(t Type) (_ *Nullable, err error) { - col.enable = true - if col.base, err = Type(t.params()).Column(col.name); err != nil { - return nil, err - } - switch base := col.base.ScanType(); { - case base == nil: - col.scanType = reflect.TypeOf(nil) - case base.Kind() == reflect.Ptr: - col.scanType = base - default: - col.scanType = reflect.New(base).Type() - } - return col, nil -} - -func (col *Nullable) Base() Interface { - return col.base -} - -func (col *Nullable) Type() Type { - return "Nullable(" + col.base.Type() + ")" -} - -func (col *Nullable) ScanType() reflect.Type { - return col.scanType -} - -func (col *Nullable) Rows() int { - if !col.enable { - return col.base.Rows() - } - return len(col.nulls.data) -} - -func (col *Nullable) Row(i int, ptr bool) interface{} { - if col.enable { - if col.nulls.data[i] == 1 { - return nil - } - } - return col.base.Row(i, true) -} - -func (col *Nullable) ScanRow(dest interface{}, row int) error { - if col.enable { - if col.nulls.data[row] == 1 { - return nil - } - } - return col.base.ScanRow(dest, row) -} - -func (col *Nullable) Append(v interface{}) ([]uint8, error) { - nulls, err := col.base.Append(v) - if err != nil { - return nil, err - } - col.nulls.data = append(col.nulls.data, nulls...) - return nulls, nil -} - -func (col *Nullable) AppendRow(v interface{}) error { - if v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil()) { - col.nulls.data = append(col.nulls.data, 1) - } else { - col.nulls.data = append(col.nulls.data, 0) - } - return col.base.AppendRow(v) -} - -func (col *Nullable) Decode(decoder *binary.Decoder, rows int) (err error) { - if col.enable { - if err := col.nulls.Decode(decoder, rows); err != nil { - return err - } - } - if err := col.base.Decode(decoder, rows); err != nil { - return err - } - return nil -} - -func (col *Nullable) Encode(encoder *binary.Encoder) error { - if col.enable { - if err := col.nulls.Encode(encoder); err != nil { - return err - } - } - if err := col.base.Encode(encoder); err != nil { - return err - } - return nil -} - -var _ Interface = (*Nullable)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/simple_aggregate_function.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/simple_aggregate_function.go deleted file mode 100644 index 87693c68db..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/simple_aggregate_function.go +++ /dev/null @@ -1,76 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "reflect" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type SimpleAggregateFunction struct { - base Interface - chType Type - name string -} - -func (col *SimpleAggregateFunction) Name() string { - return col.name -} - -func (col *SimpleAggregateFunction) parse(t Type) (_ Interface, err error) { - col.chType = t - base := strings.TrimSpace(strings.SplitN(t.params(), ",", 2)[1]) - if col.base, err = Type(base).Column(col.name); err == nil { - return col, nil - } - return nil, &UnsupportedColumnTypeError{ - t: t, - } -} - -func (col *SimpleAggregateFunction) Type() Type { - return col.chType -} -func (col *SimpleAggregateFunction) ScanType() reflect.Type { - return col.base.ScanType() -} -func (col *SimpleAggregateFunction) Rows() int { - return col.base.Rows() -} -func (col *SimpleAggregateFunction) Row(i int, ptr bool) interface{} { - return col.base.Row(i, ptr) -} -func (col *SimpleAggregateFunction) ScanRow(dest interface{}, rows int) error { - return col.base.ScanRow(dest, rows) -} -func (col *SimpleAggregateFunction) Append(v interface{}) ([]uint8, error) { - return col.base.Append(v) -} -func (col *SimpleAggregateFunction) AppendRow(v interface{}) error { - return col.base.AppendRow(v) -} -func (col *SimpleAggregateFunction) Decode(decoder *binary.Decoder, rows int) error { - return col.base.Decode(decoder, rows) -} -func (col *SimpleAggregateFunction) Encode(encoder *binary.Encoder) error { - return col.base.Encode(encoder) -} - -var _ Interface = (*SimpleAggregateFunction)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/slice_helper.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/slice_helper.go deleted file mode 100644 index ae7a3c99c0..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/slice_helper.go +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -// difference returns the elements in `a` that aren't in `b`. -func difference(a, b []string) []string { - mb := make(map[string]struct{}, len(b)) - for _, x := range b { - mb[x] = struct{}{} - } - var diff []string - for _, x := range a { - if _, found := mb[x]; !found { - diff = append(diff, x) - } - } - return diff -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/string.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/string.go deleted file mode 100644 index 9b4261b285..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/string.go +++ /dev/null @@ -1,143 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "encoding" - "fmt" - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "reflect" -) - -type String struct { - name string - data []string -} - -func (col String) Name() string { - return col.name -} - -func (String) Type() Type { - return "String" -} - -func (String) ScanType() reflect.Type { - return scanTypeString -} - -func (col *String) Rows() int { - return len(col.data) -} - -func (col *String) Row(i int, ptr bool) interface{} { - value := *col - if ptr { - return &value.data[i] - } - return value.data[i] -} - -func (col *String) ScanRow(dest interface{}, row int) error { - v := *col - switch d := dest.(type) { - case *string: - *d = v.data[row] - case **string: - *d = new(string) - **d = v.data[row] - case encoding.BinaryUnmarshaler: - return d.UnmarshalBinary(binary.Str2Bytes(v.data[row])) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "String", - } - } - return nil -} - -func (col *String) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []string: - col.data, nulls = append(col.data, v...), make([]uint8, len(v)) - case []*string: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data, nulls[i] = append(col.data, ""), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "String", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *String) AppendRow(v interface{}) error { - switch v := v.(type) { - case string: - col.data = append(col.data, v) - case *string: - switch { - case v != nil: - col.data = append(col.data, *v) - default: - col.data = append(col.data, "") - } - case nil: - col.data = append(col.data, "") - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "String", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *String) Decode(decoder *binary.Decoder, rows int) error { - for i := 0; i < rows; i++ { - v, err := decoder.String() - if err != nil { - return err - } - col.data = append(col.data, v) - } - return nil -} - -func (col *String) Encode(encoder *binary.Encoder) error { - for _, v := range col.data { - if err := encoder.String(v); err != nil { - return err - } - } - return nil -} - -var _ Interface = (*String)(nil) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/tuple.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/tuple.go deleted file mode 100644 index 9e5c50004c..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/tuple.go +++ /dev/null @@ -1,533 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "github.com/google/uuid" - "github.com/shopspring/decimal" - "net" - "reflect" - "strings" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Tuple struct { - chType Type - columns []Interface - name string -} - -func (col *Tuple) Name() string { - return col.name -} - -type namedCol struct { - name string - colType Type -} - -func (col *Tuple) parse(t Type) (_ Interface, err error) { - col.chType = t - var ( - element []rune - elements []namedCol - brackets int - appendElement = func() { - if len(element) != 0 { - cType := strings.TrimSpace(string(element)) - name := "" - if parts := strings.SplitN(cType, " ", 2); len(parts) == 2 { - if !strings.Contains(parts[0], "(") { - name = parts[0] - cType = parts[1] - } - } - elements = append(elements, namedCol{ - name: name, - colType: Type(strings.TrimSpace(cType)), - }) - } - } - ) - for _, r := range t.params() { - switch r { - case '(': - brackets++ - case ')': - brackets-- - case ',': - if brackets == 0 { - appendElement() - element = element[:0] - continue - } - } - element = append(element, r) - } - appendElement() - for _, ct := range elements { - column, err := ct.colType.Column(ct.name) - if err != nil { - return nil, err - } - col.columns = append(col.columns, column) - } - if len(col.columns) != 0 { - return col, nil - } - return nil, &UnsupportedColumnTypeError{ - t: t, - } -} - -func (col *Tuple) Type() Type { - return col.chType -} - -func (Tuple) ScanType() reflect.Type { - return scanTypeSlice -} - -func (col *Tuple) Rows() int { - if len(col.columns) != 0 { - return col.columns[0].Rows() - } - return 0 -} - -func (col *Tuple) Row(i int, ptr bool) interface{} { - tuple := make([]interface{}, 0, len(col.columns)) - for _, c := range col.columns { - tuple = append(tuple, c.Row(i, ptr)) - } - return tuple -} - -func setJSONFieldValue(field reflect.Value, value reflect.Value) error { - switch field.Interface().(type) { - case time.Time: - if value.Kind() == reflect.String { - sValue := value.Interface().(string) - val, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", sValue) - if err != nil { - return &Error{ - ColumnType: fmt.Sprint(field.Type()), - Err: fmt.Errorf("%s cannot be parsed into a time.Time as it isn't in the default format [2006-01-02 15:04:05.999999999 -0700 MST]", sValue), - } - } - field.Set(reflect.ValueOf(val)) - return nil - } - case decimal.Decimal: - if value.Kind() == reflect.String { - sValue := value.Interface().(string) - var val decimal.Decimal - if sValue == "" { - field.Set(reflect.ValueOf(val)) - return nil - } - val, err := decimal.NewFromString(sValue) - if err != nil { - return &Error{ - ColumnType: fmt.Sprint(field.Type()), - Err: fmt.Errorf("value %s but cannot be parsed into a decimal.Decimal - %s", sValue, err), - } - } - field.Set(reflect.ValueOf(val)) - return nil - } - case net.IP: - if value.Kind() == reflect.String { - sValue := value.Interface().(string) - field.Set(reflect.ValueOf(net.ParseIP(sValue))) - return nil - } - case uuid.UUID: - if value.Kind() == reflect.String { - sValue := value.Interface().(string) - uuid, err := uuid.Parse(sValue) - if err != nil { - return &Error{ - ColumnType: fmt.Sprint(field.Type()), - Err: fmt.Errorf("value %s cannot be parsed into a uuid.UUID - %s", sValue, err), - } - } - field.Set(reflect.ValueOf(uuid)) - return nil - } - } - - // check if our target is a string - if field.Kind() == reflect.String { - field.Set(reflect.ValueOf(fmt.Sprint(value.Interface()))) - return nil - } - if value.CanConvert(field.Type()) { - field.Set(value.Convert(field.Type())) - return nil - } - - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", field.Interface()), - From: value.Type().String(), - } - -} - -func getStructFieldValue(field reflect.Value, name string) (reflect.Value, bool) { - tField := field.Type() - for i := 0; i < tField.NumField(); i++ { - if jsonTag := tField.Field(i).Tag.Get("json"); jsonTag == name { - return field.Field(i), true - } - } - sField := field.FieldByName(name) - return sField, sField.IsValid() -} - -func (col *Tuple) scanJSONMap(json reflect.Value, row int) error { - if json.Type().Key().Kind() != reflect.String { - return &Error{ - ColumnType: fmt.Sprint(json.Type().Key().Kind()), - Err: fmt.Errorf("column %s - map keys must be a string", col.Name()), - } - } - for _, c := range col.columns { - switch dCol := c.(type) { - case *Tuple: - switch json.Type().Elem().Kind() { - case reflect.Struct: - rStruct := reflect.New(json.Type().Elem()).Elem() - if err := dCol.scanJSONStruct(rStruct, row); err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), rStruct) - case reflect.Map: - // get a typed map - newMap := reflect.MakeMap(json.Type().Elem()) - if err := dCol.scanJSONMap(newMap, row); err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), newMap) - case reflect.Interface: - // catches interface{} - Note this swallows custom interfaces to which maps couldn't conform - newMap := reflect.ValueOf(make(map[string]interface{})) - if err := dCol.scanJSONMap(newMap, row); err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), newMap) - default: - return &Error{ - ColumnType: fmt.Sprint(json.Type().Elem().Kind()), - Err: fmt.Errorf("column %s - needs a map/struct or interface{}", col.Name()), - } - } - case *Nested: - aCol := dCol.Interface.(*Array) - subSlice, err := aCol.parseJSONSliceOfObjects(json.Type().Elem(), row) - if err != nil { - return err - } - // this wont work if json is a map[string][]interface{} and we try to set a typed slice - json.SetMapIndex(reflect.ValueOf(c.Name()), subSlice) - case *Array: - switch dCol.values.(type) { - case *Tuple: - // eqv. of nested - subSlice, err := dCol.parseJSONSliceOfObjects(json.Type().Elem(), row) - if err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), subSlice) - default: - // this will include nested Arrays which if primitive types can be nested deep - switch json.Type().Elem().Kind() { - case reflect.Slice: - subSlice, err := dCol.scanJSONSlice(json.Type().Elem(), row, 0) - if err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), subSlice) - case reflect.Interface: - // we assume interface{} - any other custom interfaces will fail - field := reflect.New(reflect.TypeOf(c.Row(0, false))).Elem() - value := reflect.ValueOf(c.Row(row, false)) - if err := setJSONFieldValue(field, value); err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), field) - default: - return &Error{ - ColumnType: fmt.Sprint(json.Type().Elem().Kind()), - Err: fmt.Errorf("column %s - needs a slice or interface{}", col.Name()), - } - } - } - default: - field := reflect.New(reflect.TypeOf(c.Row(0, false))).Elem() - value := reflect.ValueOf(c.Row(row, false)) - if err := setJSONFieldValue(field, value); err != nil { - return err - } - json.SetMapIndex(reflect.ValueOf(c.Name()), field) - } - } - return nil -} - -func (col *Tuple) scanJSONStruct(json reflect.Value, row int) error { - for _, c := range col.columns { - // the column may be serialized using a different name due to a struct "json" tag - sField, ok := getStructFieldValue(json, c.Name()) - // test if map - if !ok { - continue - } - switch dCol := c.(type) { - case *Tuple: - switch sField.Kind() { - case reflect.Struct: - if err := dCol.scanJSONStruct(sField, row); err != nil { - return err - } - case reflect.Map: - newMap := reflect.MakeMap(sField.Type()) - if err := dCol.scanJSONMap(newMap, row); err != nil { - return err - } - sField.Set(newMap) - case reflect.Interface: - // catches []interface{} -Note this swallows custom interfaces to which maps couldn't conform - newMap := reflect.ValueOf(make(map[string]interface{})) - if err := dCol.scanJSONMap(newMap, row); err != nil { - return err - } - sField.Set(newMap) - default: - return &Error{ - ColumnType: fmt.Sprint(sField.Kind()), - Err: fmt.Errorf("column %s - needs a map/struct or interface{}", col.Name()), - } - } - case *Nested: - aCol := dCol.Interface.(*Array) - subSlice, err := aCol.parseJSONSliceOfObjects(sField.Type(), row) - if err != nil { - return err - } - sField.Set(subSlice) - case *Array: - switch dCol.values.(type) { - case *Tuple: - //eqv of nested - subSlice, err := dCol.parseJSONSliceOfObjects(sField.Type(), row) - if err != nil { - return err - } - sField.Set(subSlice) - default: - // slice of primitives - switch sField.Kind() { - case reflect.Slice: - subSlice, err := dCol.scanJSONSlice(sField.Type(), row, 0) - if err != nil { - return err - } - sField.Set(subSlice) - case reflect.Interface: - value := reflect.ValueOf(c.Row(row, false)) - if err := setJSONFieldValue(sField, value); err != nil { - return err - } - default: - return &Error{ - ColumnType: fmt.Sprint(json.Type().Elem().Kind()), - Err: fmt.Errorf("column %s - needs a slice or interface{}", col.Name()), - } - } - - } - default: - value := reflect.ValueOf(c.Row(row, false)) - if err := setJSONFieldValue(sField, value); err != nil { - return err - } - } - } - return nil -} - -func (col *Tuple) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *[]interface{}: - tuple := make([]interface{}, 0, len(col.columns)) - for _, c := range col.columns { - tuple = append(tuple, c.Row(row, false)) - } - *d = tuple - default: - jType := reflect.Indirect(reflect.ValueOf(dest)) - kind := jType.Kind() - if kind == reflect.Struct { - rStruct := reflect.New(jType.Type()).Elem() - err := col.scanJSONStruct(rStruct, row) - if err != nil { - return err - } - jType.Set(rStruct) - return nil - } - if kind == reflect.Map { - //check if pointer - mapVal := reflect.Indirect(reflect.ValueOf(dest)) - if mapVal.IsNil() { - //if not initialized - newMap := reflect.MakeMap(mapVal.Type()) - if err := col.scanJSONMap(newMap, row); err != nil { - return err - } - mapVal.Set(newMap) - return nil - } - return col.scanJSONMap(mapVal, row) - } - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: string(col.chType), - } - } - return nil -} - -func (col *Tuple) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case [][]interface{}: - for _, v := range v { - if err := col.AppendRow(v); err != nil { - return nil, err - } - } - return nil, nil - case []*[]interface{}: - for _, v := range v { - if err := col.AppendRow(v); err != nil { - return nil, err - } - } - return nil, nil - } - return nil, &ColumnConverterError{ - Op: "Append", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } -} - -func (col *Tuple) AppendRow(v interface{}) error { - switch v := v.(type) { - case []interface{}: - if len(v) != len(col.columns) { - return &Error{ - ColumnType: string(col.chType), - Err: fmt.Errorf("invalid size. expected %d got %d", len(col.columns), len(v)), - } - } - for i, v := range v { - if err := col.columns[i].AppendRow(v); err != nil { - return err - } - } - return nil - case *[]interface{}: - if v == nil { - return &ColumnConverterError{ - Op: "AppendRow", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - Hint: "invalid (nil) pointer value", - } - } - if len(*v) != len(col.columns) { - return &Error{ - ColumnType: string(col.chType), - Err: fmt.Errorf("invalid size. expected %d got %d", len(col.columns), len(*v)), - } - } - for i, v := range *v { - if err := col.columns[i].AppendRow(v); err != nil { - return err - } - } - return nil - } - return &ColumnConverterError{ - Op: "AppendRow", - To: string(col.chType), - From: fmt.Sprintf("%T", v), - } -} - -func (col *Tuple) Decode(decoder *binary.Decoder, rows int) error { - for _, c := range col.columns { - if err := c.Decode(decoder, rows); err != nil { - return err - } - } - return nil -} - -func (col *Tuple) Encode(encoder *binary.Encoder) error { - for _, c := range col.columns { - if err := c.Encode(encoder); err != nil { - return err - } - } - return nil -} - -func (col *Tuple) ReadStatePrefix(decoder *binary.Decoder) error { - for _, c := range col.columns { - if serialize, ok := c.(CustomSerialization); ok { - if err := serialize.ReadStatePrefix(decoder); err != nil { - return err - } - } - } - return nil -} - -func (col *Tuple) WriteStatePrefix(encoder *binary.Encoder) error { - for _, c := range col.columns { - if serialize, ok := c.(CustomSerialization); ok { - if err := serialize.WriteStatePrefix(encoder); err != nil { - return err - } - } - } - return nil -} - -var ( - _ Interface = (*Tuple)(nil) - _ CustomSerialization = (*Tuple)(nil) -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/uuid.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/uuid.go deleted file mode 100644 index 62ec9e223a..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/column/uuid.go +++ /dev/null @@ -1,157 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package column - -import ( - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/google/uuid" -) - -const uuidSize = 16 - -type UUID struct { - data []byte - name string -} - -func (col *UUID) Name() string { - return col.name -} - -func (col *UUID) Type() Type { - return "UUID" -} - -func (col *UUID) ScanType() reflect.Type { - return scanTypeUUID -} - -func (col *UUID) Rows() int { - return len(col.data) / uuidSize -} - -func (col *UUID) Row(i int, ptr bool) interface{} { - value := col.row(i) - if ptr { - return &value - } - return value -} - -func (col *UUID) ScanRow(dest interface{}, row int) error { - switch d := dest.(type) { - case *uuid.UUID: - *d = col.row(row) - case **uuid.UUID: - *d = new(uuid.UUID) - **d = col.row(row) - default: - return &ColumnConverterError{ - Op: "ScanRow", - To: fmt.Sprintf("%T", dest), - From: "UUID", - Hint: fmt.Sprintf("try using *%s", col.ScanType()), - } - } - return nil -} - -func (col *UUID) Append(v interface{}) (nulls []uint8, err error) { - switch v := v.(type) { - case []uuid.UUID: - nulls = make([]uint8, len(v)) - for _, v := range v { - col.data = append(col.data, swap(v[:])...) - } - case []*uuid.UUID: - nulls = make([]uint8, len(v)) - for i, v := range v { - switch { - case v != nil: - tmp := *v - col.data = append(col.data, swap(tmp[:])...) - default: - col.data, nulls[i] = append(col.data, make([]byte, uuidSize)...), 1 - } - } - default: - return nil, &ColumnConverterError{ - Op: "Append", - To: "UUID", - From: fmt.Sprintf("%T", v), - } - } - return -} - -func (col *UUID) AppendRow(v interface{}) error { - switch v := v.(type) { - case uuid.UUID: - col.data = append(col.data, swap(v[:])...) - case *uuid.UUID: - switch { - case v != nil: - tmp := *v - col.data = append(col.data, swap(tmp[:])...) - default: - col.data = append(col.data, make([]byte, uuidSize)...) - } - case nil: - col.data = append(col.data, make([]byte, uuidSize)...) - default: - return &ColumnConverterError{ - Op: "AppendRow", - To: "UUID", - From: fmt.Sprintf("%T", v), - } - } - return nil -} - -func (col *UUID) Decode(decoder *binary.Decoder, rows int) error { - col.data = make([]byte, uuidSize*rows) - return decoder.Raw(col.data) -} - -func (col *UUID) Encode(encoder *binary.Encoder) error { - return encoder.Raw(col.data) -} - -func (col *UUID) row(i int) (uuid uuid.UUID) { - copy(uuid[:], col.data[i*uuidSize:(i+1)*uuidSize]) - swap(uuid[:]) - return -} - -var _ Interface = (*UUID)(nil) - -func swap(src []byte) []byte { - _ = src[15] - src[0], src[7] = src[7], src[0] - src[1], src[6] = src[6], src[1] - src[2], src[5] = src[5], src[2] - src[3], src[4] = src[4], src[3] - src[8], src[15] = src[15], src[8] - src[9], src[14] = src[14], src[9] - src[10], src[13] = src[13], src[10] - src[11], src[12] = src[12], src[11] - return src -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress.go deleted file mode 100644 index cfa169807f..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress.go +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package compress - -import ( - "encoding/binary" -) - -var endian = binary.LittleEndian - -type Method byte - -const ( - NONE Method = 0x02 - LZ4 = 0x82 - ZSTD = 0x90 -) - -const ( - // ChecksumSize is 128bits for cityhash102 checksum - checksumSize = 16 - // CompressHeader magic + compressed_size + uncompressed_size - compressHeaderSize = 1 + 4 + 4 - headerSize = checksumSize + compressHeaderSize - maxBlockSize = 1 << 20 -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress_reader.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress_reader.go deleted file mode 100644 index 68be5c540d..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress_reader.go +++ /dev/null @@ -1,111 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package compress - -import ( - "fmt" - "io" - - "github.com/pierrec/lz4/v4" -) - -func NewReader(r io.Reader) *Reader { - return &Reader{ - r: r, - pos: maxBlockSize, - data: make([]byte, maxBlockSize), - zdata: make([]byte, lz4.CompressBlockBound(maxBlockSize)+headerSize), - header: make([]byte, headerSize), - } -} - -type Reader struct { - r io.Reader - pos int - data []byte - zdata []byte - header []byte -} - -func (r *Reader) Read(p []byte) (int, error) { - bytesRead, n := 0, len(p) - if r.pos < len(r.data) { - copyedSize := copy(p, r.data[r.pos:]) - { - bytesRead += copyedSize - r.pos += copyedSize - } - } - for bytesRead < n { - if err := r.readBlock(); err != nil { - return bytesRead, err - } - copyedSize := copy(p[bytesRead:], r.data) - { - bytesRead += copyedSize - r.pos = copyedSize - } - } - return n, nil -} - -func (r *Reader) readBlock() (err error) { - r.pos = 0 - var n int - if n, err = io.ReadFull(r.r, r.header); err != nil { - return - } - if n != len(r.header) { - return fmt.Errorf("LZ4 decompression header EOF") - } - var ( - compressedSize = int(endian.Uint32(r.header[17:])) - 9 - decompressedSize = int(endian.Uint32(r.header[21:])) - ) - if compressedSize > cap(r.zdata) { - r.zdata = make([]byte, compressedSize) - } - if decompressedSize > cap(r.data) { - r.data = make([]byte, decompressedSize) - } - - r.data, r.zdata = r.data[:decompressedSize], r.zdata[:compressedSize] - - switch r.header[16] { - case LZ4: - default: - return fmt.Errorf("unknown compression method: 0x%02x ", r.header[16]) - } - // @TODO checksum - if n, err = io.ReadFull(r.r, r.zdata); err != nil { - return - } - if n != len(r.zdata) { - return fmt.Errorf("decompress read size not match") - } - if _, err = lz4.UncompressBlock(r.zdata, r.data); err != nil { - return - } - return nil -} - -func (r *Reader) Close() error { - r.data = nil - r.zdata = nil - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress_writer.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress_writer.go deleted file mode 100644 index 1fb9f7c1d3..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/compress/compress_writer.go +++ /dev/null @@ -1,91 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package compress - -import ( - "io" - - "github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102" - "github.com/pierrec/lz4/v4" -) - -func NewWriter(wr io.Writer) *Writer { - return &Writer{ - wr: wr, - data: make([]byte, maxBlockSize), - zdata: make([]byte, lz4.CompressBlockBound(maxBlockSize)+headerSize), - } -} - -type Writer struct { - wr io.Writer - pos int - data []byte - zdata []byte - compressor lz4.Compressor -} - -func (w *Writer) Write(p []byte) (n int, err error) { - for len(p) > 0 { - m := copy(w.data[w.pos:], p) - w.pos += m - p = p[m:] - if w.pos == len(w.data) { - if err = w.Flush(); err != nil { - return n, err - } - } - n += m - } - return n, nil -} - -func (w *Writer) Flush() (err error) { - if w.pos == 0 { - return - } - compressedSize, err := w.compressor.CompressBlock(w.data[:w.pos], w.zdata[headerSize:]) - if err != nil { - return err - } - compressedSize += compressHeaderSize - // fill the header, compressed_size_32 + uncompressed_size_32 - w.zdata[16] = LZ4 - endian.PutUint32(w.zdata[17:], uint32(compressedSize)) - endian.PutUint32(w.zdata[21:], uint32(w.pos)) - // fill the checksum - checkSum := cityhash102.CityHash128(w.zdata[16:], uint32(compressedSize)) - { - endian.PutUint64(w.zdata[0:], checkSum.Lower64()) - endian.PutUint64(w.zdata[8:], checkSum.Higher64()) - } - if _, err := w.wr.Write(w.zdata[:compressedSize+checksumSize]); err != nil { - return err - } - /*if w, ok := cw.writer.(WriteFlusher); ok { - err = w.Flush() - }*/ - w.pos = 0 - return -} - -func (w *Writer) Close() error { - w.data = nil - w.zdata = nil - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/driver/driver.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/driver/driver.go deleted file mode 100644 index 629512b4e0..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/driver/driver.go +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package driver - -import ( - "context" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -type ServerVersion = proto.ServerHandshake - -type ( - NamedValue struct { - Name string - Value interface{} - } - Stats struct { - MaxOpenConns int - MaxIdleConns int - Open int - Idle int - } -) - -type ( - Conn interface { - Contributors() []string - ServerVersion() (*ServerVersion, error) - Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error - Query(ctx context.Context, query string, args ...interface{}) (Rows, error) - QueryRow(ctx context.Context, query string, args ...interface{}) Row - PrepareBatch(ctx context.Context, query string) (Batch, error) - Exec(ctx context.Context, query string, args ...interface{}) error - AsyncInsert(ctx context.Context, query string, wait bool) error - Ping(context.Context) error - Stats() Stats - Close() error - } - Row interface { - Err() error - Scan(dest ...interface{}) error - ScanStruct(dest interface{}) error - } - Rows interface { - Next() bool - Scan(dest ...interface{}) error - ScanStruct(dest interface{}) error - ColumnTypes() []ColumnType - Totals(dest ...interface{}) error - Columns() []string - Close() error - Err() error - } - Batch interface { - Abort() error - Append(v ...interface{}) error - AppendStruct(v interface{}) error - Column(int) BatchColumn - Send() error - } - BatchColumn interface { - Append(interface{}) error - } - ColumnType interface { - Name() string - Nullable() bool - ScanType() reflect.Type - DatabaseTypeName() string - } -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/io/stream.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/io/stream.go deleted file mode 100644 index ead3ce2c7b..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/io/stream.go +++ /dev/null @@ -1,82 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package io - -import ( - "bufio" - "io" - - "github.com/ClickHouse/clickhouse-go/v2/lib/compress" -) - -const ( - maxReaderSize = 1 << 20 - maxWriterSize = 1 << 20 -) - -func NewStream(rw io.ReadWriter) *Stream { - stream := Stream{ - r: bufio.NewReaderSize(rw, maxReaderSize), - w: bufio.NewWriterSize(rw, maxWriterSize), - } - stream.compress.r = compress.NewReader(stream.r) - stream.compress.w = compress.NewWriter(stream.w) - return &stream -} - -type Stream struct { - r *bufio.Reader - w *bufio.Writer - compress struct { - enable bool - r *compress.Reader - w *compress.Writer - } -} - -func (s *Stream) Compress(v bool) { - s.compress.enable = v -} - -func (s *Stream) Read(p []byte) (int, error) { - if s.compress.enable { - return io.ReadFull(s.compress.r, p) - } - return io.ReadFull(s.r, p) -} - -func (s *Stream) Write(p []byte) (int, error) { - if s.compress.enable { - return s.compress.w.Write(p) - } - return s.w.Write(p) -} - -func (s *Stream) Flush() error { - if err := s.compress.w.Flush(); err != nil { - return err - } - return s.w.Flush() -} - -func (s *Stream) Close() error { - s.r, s.w = nil, nil - s.compress.r.Close() - s.compress.w.Close() - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/block.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/block.go deleted file mode 100644 index ca25f89aec..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/block.go +++ /dev/null @@ -1,239 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - "errors" - "fmt" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/ClickHouse/clickhouse-go/v2/lib/column" -) - -type Block struct { - names []string - Packet byte - Columns []column.Interface -} - -func (b *Block) Rows() int { - if len(b.Columns) == 0 { - return 0 - } - return b.Columns[0].Rows() -} - -func (b *Block) AddColumn(name string, ct column.Type) error { - column, err := ct.Column(name) - if err != nil { - return err - } - b.names, b.Columns = append(b.names, name), append(b.Columns, column) - return nil -} - -func (b *Block) Append(v ...interface{}) (err error) { - columns := b.Columns - if len(columns) != len(v) { - return &BlockError{ - Op: "Append", - Err: fmt.Errorf("clickhouse: expected %d arguments, got %d", len(columns), len(v)), - } - } - for i, v := range v { - if err := b.Columns[i].AppendRow(v); err != nil { - return &BlockError{ - Op: "AppendRow", - Err: err, - ColumnName: columns[i].Name(), - } - } - } - return nil -} - -func (b *Block) ColumnsNames() []string { - return b.names -} - -func (b *Block) Encode(encoder *binary.Encoder, revision uint64) error { - if revision > 0 { - if err := encodeBlockInfo(encoder); err != nil { - return err - } - } - var rows int - if len(b.Columns) != 0 { - rows = b.Columns[0].Rows() - for _, c := range b.Columns[1:] { - if rows != c.Rows() { - return &BlockError{ - Op: "Encode", - Err: errors.New("mismatched len of columns"), - } - } - } - } - if err := encoder.Uvarint(uint64(len(b.Columns))); err != nil { - return err - } - if err := encoder.Uvarint(uint64(rows)); err != nil { - return err - } - for _, c := range b.Columns { - if err := encoder.String(c.Name()); err != nil { - return err - } - if err := encoder.String(string(c.Type())); err != nil { - return err - } - if serialize, ok := c.(column.CustomSerialization); ok { - if err := serialize.WriteStatePrefix(encoder); err != nil { - return &BlockError{ - Op: "Encode", - Err: err, - ColumnName: c.Name(), - } - } - } - if err := c.Encode(encoder); err != nil { - return &BlockError{ - Op: "Encode", - Err: err, - ColumnName: c.Name(), - } - } - } - return nil -} - -func (b *Block) Decode(decoder *binary.Decoder, revision uint64) (err error) { - if revision > 0 { - if err := decodeBlockInfo(decoder); err != nil { - return err - } - } - var ( - numRows uint64 - numCols uint64 - ) - if numCols, err = decoder.Uvarint(); err != nil { - return err - } - if numRows, err = decoder.Uvarint(); err != nil { - return err - } - if numRows > 1_000_000_000 { - return &BlockError{ - Op: "Decode", - Err: errors.New("more then 1 billion rows in block"), - } - } - b.Columns = make([]column.Interface, 0, numCols) - for i := 0; i < int(numCols); i++ { - var ( - columnName string - columnType string - ) - if columnName, err = decoder.String(); err != nil { - return err - } - if columnType, err = decoder.String(); err != nil { - return err - } - c, err := column.Type(columnType).Column(columnName) - if err != nil { - return err - } - if numRows != 0 { - if serialize, ok := c.(column.CustomSerialization); ok { - if err := serialize.ReadStatePrefix(decoder); err != nil { - return &BlockError{ - Op: "Decode", - Err: err, - ColumnName: columnName, - } - } - } - if err := c.Decode(decoder, int(numRows)); err != nil { - return &BlockError{ - Op: "Decode", - Err: err, - ColumnName: columnName, - } - } - } - b.names, b.Columns = append(b.names, columnName), append(b.Columns, c) - } - return nil -} - -func encodeBlockInfo(encoder *binary.Encoder) error { - { - if err := encoder.Uvarint(1); err != nil { - return err - } - if err := encoder.Bool(false); err != nil { - return err - } - if err := encoder.Uvarint(2); err != nil { - return err - } - if err := encoder.Int32(-1); err != nil { - return err - } - } - return encoder.Uvarint(0) -} - -func decodeBlockInfo(decoder *binary.Decoder) error { - { - if _, err := decoder.Uvarint(); err != nil { - return err - } - if _, err := decoder.Bool(); err != nil { - return err - } - if _, err := decoder.Uvarint(); err != nil { - return err - } - if _, err := decoder.Int32(); err != nil { - return err - } - } - if _, err := decoder.Uvarint(); err != nil { - return err - } - return nil -} - -type BlockError struct { - Op string - Err error - ColumnName string -} - -func (e *BlockError) Error() string { - switch err := e.Err.(type) { - case *column.Error: - return fmt.Sprintf("clickhouse [%s]: (%s %s) %s", e.Op, e.ColumnName, err.ColumnType, err.Err) - case *column.DateOverflowError: - return fmt.Sprintf("clickhouse: dateTime overflow. %s must be between %s and %s", e.ColumnName, err.Min.Format(err.Format), err.Max.Format(err.Format)) - } - return fmt.Sprintf("clickhouse [%s]: %s %s", e.Op, e.ColumnName, e.Err) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/const.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/const.go deleted file mode 100644 index 6eac3cdf67..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/const.go +++ /dev/null @@ -1,78 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -// see https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Protocol.h -const ( - DBMS_MIN_REVISION_WITH_CLIENT_INFO = 54032 - DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE = 54058 - DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO = 54060 - DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME = 54372 - DBMS_MIN_REVISION_WITH_VERSION_PATCH = 54401 - DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO = 54420 - DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS = 54429 - DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET = 54441 - DBMS_MIN_REVISION_WITH_OPENTELEMETRY = 54442 - DBMS_MIN_PROTOCOL_VERSION_WITH_DISTRIBUTED_DEPTH = 54448 - DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME = 54449 - DBMS_MIN_PROTOCOL_VERSION_WITH_INCREMENTAL_PROFILE_EVENTS = 54451 - DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS = 54453 - DBMS_TCP_PROTOCOL_VERSION = DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS -) - -const ( - ClientHello = 0 - ClientQuery = 1 - ClientData = 2 - ClientCancel = 3 - ClientPing = 4 -) - -const ( - ClientQueryNone = 0 - ClientQueryInitial = 1 - ClientQuerySecondary = 2 -) - -const ( - CompressEnable uint64 = 1 - CompressDisable uint64 = 0 -) - -const ( - StateComplete = 2 -) - -const ( - ServerHello = 0 - ServerData = 1 - ServerException = 2 - ServerProgress = 3 - ServerPong = 4 - ServerEndOfStream = 5 - ServerProfileInfo = 6 - ServerTotals = 7 - ServerExtremes = 8 - ServerTablesStatus = 9 - ServerLog = 10 - ServerTableColumns = 11 - ServerPartUUIDs = 12 - ServerReadTaskRequest = 13 - ServerProfileEvents = 14 - ServerTreeReadTaskRequest = 15 -) diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/exception.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/exception.go deleted file mode 100644 index c58bef0d02..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/exception.go +++ /dev/null @@ -1,81 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - "fmt" - "strings" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Exception struct { - Code int32 - Name string - Message string - StackTrace string - Nested []Exception - nested bool -} - -func (e *Exception) Error() string { - return fmt.Sprintf("code: %d, message: %s", e.Code, e.Message) -} - -func (e *Exception) Decode(decoder *binary.Decoder) (err error) { - var exceptions []Exception - for { - var ex Exception - if err := ex.decode(decoder); err != nil { - return err - } - if exceptions = append(exceptions, ex); !ex.nested { - break - } - } - if len(exceptions) != 0 { - e.Code = exceptions[0].Code - e.Name = exceptions[0].Name - e.Message = exceptions[0].Message - e.StackTrace = exceptions[0].StackTrace - if exceptions[0].nested { - e.Nested = exceptions[1:] - } - } - return nil -} - -func (e *Exception) decode(decoder *binary.Decoder) (err error) { - if e.Code, err = decoder.Int32(); err != nil { - return err - } - if e.Name, err = decoder.String(); err != nil { - return err - } - if e.Message, err = decoder.String(); err != nil { - return err - } - e.Message = strings.TrimSpace(strings.TrimPrefix(e.Message, e.Name+":")) - if e.StackTrace, err = decoder.String(); err != nil { - return err - } - if e.nested, err = decoder.Bool(); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/handshake.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/handshake.go deleted file mode 100644 index e82957b417..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/handshake.go +++ /dev/null @@ -1,112 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - "fmt" - "time" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "github.com/ClickHouse/clickhouse-go/v2/lib/timezone" -) - -const ClientName = "Golang SQLDriver" - -const ( - ClientVersionMajor = 1 - ClientVersionMinor = 1 - ClientTCPProtocolVersion = DBMS_TCP_PROTOCOL_VERSION -) - -type ClientHandshake struct{} - -func (ClientHandshake) Encode(encoder *binary.Encoder) error { - if err := encoder.String(ClientName); err != nil { - return err - } - if err := encoder.Uvarint(ClientVersionMajor); err != nil { - return err - } - if err := encoder.Uvarint(ClientVersionMinor); err != nil { - return err - } - return encoder.Uvarint(ClientTCPProtocolVersion) -} - -func (ClientHandshake) String() string { - return fmt.Sprintf("%s %d.%d.%d", ClientName, ClientVersionMajor, ClientVersionMinor, ClientTCPProtocolVersion) -} - -type ServerHandshake struct { - Name string - DisplayName string - Revision uint64 - Version struct { - Major uint64 - Minor uint64 - Patch uint64 - } - Timezone *time.Location -} - -func (srv *ServerHandshake) Decode(decoder *binary.Decoder) (err error) { - if srv.Name, err = decoder.String(); err != nil { - return fmt.Errorf("could not read server name: %v", err) - } - if srv.Version.Major, err = decoder.Uvarint(); err != nil { - return fmt.Errorf("could not read server major version: %v", err) - } - if srv.Version.Minor, err = decoder.Uvarint(); err != nil { - return fmt.Errorf("could not read server minor version: %v", err) - } - if srv.Revision, err = decoder.Uvarint(); err != nil { - return fmt.Errorf("could not read server revision: %v", err) - } - if srv.Revision >= DBMS_MIN_REVISION_WITH_SERVER_TIMEZONE { - name, err := decoder.String() - if err != nil { - return fmt.Errorf("could not read server timezone: %v", err) - } - if srv.Timezone, err = timezone.Load(name); err != nil { - return fmt.Errorf("could not load time location: %v", err) - } - } - if srv.Revision >= DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME { - if srv.DisplayName, err = decoder.String(); err != nil { - return fmt.Errorf("could not read server display name: %v", err) - } - } - if srv.Revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH { - if srv.Version.Patch, err = decoder.Uvarint(); err != nil { - return fmt.Errorf("could not read server patch: %v", err) - } - } else { - srv.Version.Patch = srv.Revision - } - return nil -} - -func (srv ServerHandshake) String() string { - return fmt.Sprintf("%s (%s) server version %d.%d.%d revision %d (timezone %s)", srv.Name, srv.DisplayName, - srv.Version.Major, - srv.Version.Minor, - srv.Version.Patch, - srv.Revision, - srv.Timezone, - ) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/profile_info.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/profile_info.go deleted file mode 100644 index 5617529d68..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/profile_info.go +++ /dev/null @@ -1,66 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - "fmt" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type ProfileInfo struct { - Rows uint64 - Bytes uint64 - Blocks uint64 - AppliedLimit bool - RowsBeforeLimit uint64 - CalculatedRowsBeforeLimit bool -} - -func (p *ProfileInfo) Decode(decoder *binary.Decoder, revision uint64) (err error) { - if p.Rows, err = decoder.Uvarint(); err != nil { - return err - } - if p.Blocks, err = decoder.Uvarint(); err != nil { - return err - } - if p.Bytes, err = decoder.Uvarint(); err != nil { - return err - } - if p.AppliedLimit, err = decoder.Bool(); err != nil { - return err - } - if p.RowsBeforeLimit, err = decoder.Uvarint(); err != nil { - return err - } - if p.CalculatedRowsBeforeLimit, err = decoder.Bool(); err != nil { - return err - } - return nil -} - -func (p *ProfileInfo) String() string { - return fmt.Sprintf("rows=%d, bytes=%d, blocks=%d, rows before limit=%d, applied limit=%t, calculated rows before limit=%t", - p.Rows, - p.Bytes, - p.Blocks, - p.RowsBeforeLimit, - p.AppliedLimit, - p.CalculatedRowsBeforeLimit, - ) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/progress.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/progress.go deleted file mode 100644 index 7e77c47b86..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/progress.go +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - "fmt" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type Progress struct { - Rows uint64 - Bytes uint64 - TotalRows uint64 - WroteRows uint64 - WroteBytes uint64 - withClient bool -} - -func (p *Progress) Decode(decoder *binary.Decoder, revision uint64) (err error) { - if p.Rows, err = decoder.Uvarint(); err != nil { - return err - } - if p.Bytes, err = decoder.Uvarint(); err != nil { - return err - } - if p.TotalRows, err = decoder.Uvarint(); err != nil { - return err - } - if revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO { - p.withClient = true - if p.WroteRows, err = decoder.Uvarint(); err != nil { - return err - } - if p.WroteBytes, err = decoder.Uvarint(); err != nil { - return err - } - } - return nil -} - -func (p *Progress) String() string { - if !p.withClient { - return fmt.Sprintf("rows=%d, bytes=%d, total rows=%d", p.Rows, p.Bytes, p.TotalRows) - } - return fmt.Sprintf("rows=%d, bytes=%d, total rows=%d, wrote rows=%d wrote bytes=%d", - p.Rows, - p.Bytes, - p.TotalRows, - p.WroteRows, - p.WroteBytes, - ) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/query.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/query.go deleted file mode 100644 index 492f5c6d03..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/query.go +++ /dev/null @@ -1,169 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - stdbin "encoding/binary" - "fmt" - "os" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" - "go.opentelemetry.io/otel/trace" -) - -var ( - osUser = os.Getenv("USER") - hostname, _ = os.Hostname() -) - -type Query struct { - ID string - Span trace.SpanContext - Body string - QuotaKey string - Settings Settings - Compression bool - InitialUser string - InitialAddress string -} - -func (q *Query) Encode(encoder *binary.Encoder, revision uint64) error { - if err := encoder.String(q.ID); err != nil { - return err - } - // client_info - if err := q.encodeClientInfo(encoder, revision); err != nil { - return err - } - // settings - if err := q.Settings.Encode(encoder, revision); err != nil { - return err - } - encoder.String("" /* empty string is a marker of the end of setting */) - - if revision >= DBMS_MIN_REVISION_WITH_INTERSERVER_SECRET { - encoder.String("") - } - { - encoder.Byte(StateComplete) - encoder.Bool(q.Compression) - } - return encoder.String(q.Body) -} - -func swap64(b []byte) { - for i := 0; i < len(b); i += 8 { - u := stdbin.BigEndian.Uint64(b[i:]) - stdbin.LittleEndian.PutUint64(b[i:], u) - } -} - -func (q *Query) encodeClientInfo(encoder *binary.Encoder, revision uint64) error { - encoder.Byte(ClientQueryInitial) - encoder.String(q.InitialUser) // initial_user - encoder.String("") // initial_query_id - encoder.String(q.InitialAddress) // initial_address - if revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_INITIAL_QUERY_START_TIME { - encoder.Int64(0) // initial_query_start_time_microseconds - } - encoder.Byte(1) // interface [tcp - 1, http - 2] - { - encoder.String(osUser) - encoder.String(hostname) - encoder.String(ClientName) - encoder.Uvarint(ClientVersionMajor) - encoder.Uvarint(ClientVersionMinor) - encoder.Uvarint(ClientTCPProtocolVersion) - } - if revision >= DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO { - encoder.String(q.QuotaKey) - } - if revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_DISTRIBUTED_DEPTH { - encoder.Uvarint(0) - } - if revision >= DBMS_MIN_REVISION_WITH_VERSION_PATCH { - encoder.Uvarint(0) - } - if revision >= DBMS_MIN_REVISION_WITH_OPENTELEMETRY { - switch { - case q.Span.IsValid(): - encoder.Byte(1) - { - v := q.Span.TraceID() - swap64(v[:]) // https://github.com/ClickHouse/ClickHouse/issues/34369 - encoder.Raw(v[:]) - } - { - v := q.Span.SpanID() - swap64(v[:]) // https://github.com/ClickHouse/ClickHouse/issues/34369 - encoder.Raw(v[:]) - } - encoder.String(q.Span.TraceState().String()) - encoder.Byte(byte(q.Span.TraceFlags())) - - default: - encoder.Byte(0) - } - } - if revision >= DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS { - encoder.Uvarint(0) // collaborate_with_initiator - encoder.Uvarint(0) // count_participating_replicas - encoder.Uvarint(0) // number_of_current_replica - } - return nil -} - -type Settings []Setting - -type Setting struct { - Key string - Value interface{} -} - -func (s Settings) Encode(encoder *binary.Encoder, revision uint64) error { - for _, s := range s { - if err := s.encode(encoder, revision); err != nil { - return err - } - } - return nil -} - -func (s *Setting) encode(encoder *binary.Encoder, revision uint64) error { - if err := encoder.String(s.Key); err != nil { - return err - } - if revision <= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS { - var value uint64 - switch v := s.Value.(type) { - case int: - value = uint64(v) - case bool: - if value = 0; v { - value = 1 - } - default: - return fmt.Errorf("query setting %s has unsupported data type", s.Key) - } - return encoder.Uvarint(value) - } - if err := encoder.Bool(true); err != nil { // is_important - return err - } - return encoder.String(fmt.Sprint(s.Value)) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/table_columns.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/table_columns.go deleted file mode 100644 index 0f37d51391..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/proto/table_columns.go +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package proto - -import ( - "fmt" - - "github.com/ClickHouse/clickhouse-go/v2/lib/binary" -) - -type TableColumns struct { - First string - Second string -} - -func (t *TableColumns) Decode(decoder *binary.Decoder, revision uint64) (err error) { - if t.First, err = decoder.String(); err != nil { - return err - } - if t.Second, err = decoder.String(); err != nil { - return err - } - return nil -} - -func (t *TableColumns) String() string { - return fmt.Sprintf("first=%s, second=%s", t.First, t.Second) -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/timezone/timezone.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/timezone/timezone.go deleted file mode 100644 index 09eeffd0f4..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/lib/timezone/timezone.go +++ /dev/null @@ -1,44 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package timezone - -import ( - "sync" - "time" -) - -var cache = struct { - mutex sync.Mutex - items map[string]*time.Location -}{ - items: make(map[string]*time.Location), -} - -func Load(name string) (*time.Location, error) { - cache.mutex.Lock() - defer cache.mutex.Unlock() - if tz, found := cache.items[name]; found { - return tz, nil - } - tz, err := time.LoadLocation(name) - if err != nil { - return nil, err - } - cache.items[name] = tz - return tz, nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/scan.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/scan.go deleted file mode 100644 index bb1b1ba011..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/scan.go +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "context" - "errors" - "fmt" - "reflect" - - "github.com/ClickHouse/clickhouse-go/v2/lib/proto" -) - -func (ch *clickhouse) Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error { - value := reflect.ValueOf(dest) - if value.Kind() != reflect.Ptr { - return &OpError{ - Op: "Select", - Err: errors.New("must pass a pointer, not a value, to Select destination"), - } - } - if value.IsNil() { - return &OpError{ - Op: "Select", - Err: errors.New("nil pointer passed to Select destination"), - } - } - direct := reflect.Indirect(value) - if direct.Kind() != reflect.Slice { - return fmt.Errorf("must pass a slice to Select destination") - } - var ( - base = direct.Type().Elem() - rows, err = ch.Query(ctx, query, args...) - ) - if err != nil { - return err - } - defer rows.Close() - for rows.Next() { - elem := reflect.New(base) - if err := rows.ScanStruct(elem.Interface()); err != nil { - return err - } - direct.Set(reflect.Append(direct, elem.Elem())) - } - if err := rows.Close(); err != nil { - return err - } - return rows.Err() -} - -func scan(block *proto.Block, row int, dest ...interface{}) error { - columns := block.Columns - if len(columns) != len(dest) { - return &OpError{ - Op: "Scan", - Err: fmt.Errorf("expected %d destination arguments in Scan, not %d", len(columns), len(dest)), - } - } - for i, d := range dest { - if err := columns[i].ScanRow(d, row-1); err != nil { - return &OpError{ - Err: err, - ColumnName: block.ColumnsNames()[i], - } - } - } - return nil -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/v2/struct_map.go b/vendor/github.com/ClickHouse/clickhouse-go/v2/struct_map.go deleted file mode 100644 index 06d3947936..0000000000 --- a/vendor/github.com/ClickHouse/clickhouse-go/v2/struct_map.go +++ /dev/null @@ -1,111 +0,0 @@ -// Licensed to ClickHouse, Inc. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. ClickHouse, Inc. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package clickhouse - -import ( - "fmt" - "reflect" - "sync" -) - -type structMap struct { - cache sync.Map -} - -func (m *structMap) Map(op string, columns []string, s interface{}, ptr bool) ([]interface{}, error) { - v := reflect.ValueOf(s) - if v.Kind() != reflect.Ptr { - return nil, &OpError{ - Op: op, - Err: fmt.Errorf("must pass a pointer, not a value, to %s destination", op), - } - } - if v.IsNil() { - return nil, &OpError{ - Op: op, - Err: fmt.Errorf("nil pointer passed to %s destination", op), - } - } - t := reflect.TypeOf(s) - if v = reflect.Indirect(v); t.Kind() == reflect.Ptr { - t = t.Elem() - } - if v.Kind() != reflect.Struct { - return nil, &OpError{ - Op: op, - Err: fmt.Errorf("%s expects a struct dest", op), - } - } - - var ( - index map[string][]int - values = make([]interface{}, 0, len(columns)) - ) - - switch idx, found := m.cache.Load(t); { - case found: - index = idx.(map[string][]int) - default: - index = structIdx(t) - m.cache.Store(t, index) - } - for _, name := range columns { - idx, found := index[name] - if !found { - return nil, &OpError{ - Op: op, - Err: fmt.Errorf("missing destination name %q in %T", name, s), - } - } - switch field := v.FieldByIndex(idx); { - case ptr: - values = append(values, field.Addr().Interface()) - default: - values = append(values, field.Interface()) - } - } - return values, nil -} - -func structIdx(t reflect.Type) map[string][]int { - fields := make(map[string][]int) - for i := 0; i < t.NumField(); i++ { - var ( - f = t.Field(i) - name = f.Name - ) - if tn := f.Tag.Get("ch"); len(tn) != 0 { - name = tn - } - switch { - case name == "-", len(f.PkgPath) != 0 && !f.Anonymous: - continue - } - switch { - case f.Anonymous: - if f.Type.Kind() != reflect.Ptr { - for k, idx := range structIdx(f.Type) { - fields[k] = append(f.Index, idx...) - } - } - default: - fields[name] = f.Index - } - } - return fields -} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/word_matcher.go b/vendor/github.com/ClickHouse/clickhouse-go/word_matcher.go new file mode 100644 index 0000000000..7cd9dcd750 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/word_matcher.go @@ -0,0 +1,31 @@ +package clickhouse + +import ( + "strings" + "unicode" +) + +// wordMatcher is a simple automata to match a single word (case insensitive) +type wordMatcher struct { + word []rune + position uint8 +} + +// newMatcher returns matcher for word needle +func newMatcher(needle string) *wordMatcher { + return &wordMatcher{word: []rune(strings.ToUpper(needle)), + position: 0} +} + +func (m *wordMatcher) matchRune(r rune) bool { + if m.word[m.position] == unicode.ToUpper(r) { + if m.position == uint8(len(m.word)-1) { + m.position = 0 + return true + } + m.position++ + } else { + m.position = 0 + } + return false +} diff --git a/vendor/github.com/ClickHouse/clickhouse-go/write_column.go b/vendor/github.com/ClickHouse/clickhouse-go/write_column.go new file mode 100644 index 0000000000..eb4f0fe3b3 --- /dev/null +++ b/vendor/github.com/ClickHouse/clickhouse-go/write_column.go @@ -0,0 +1,66 @@ +package clickhouse + +import ( + "database/sql" + "database/sql/driver" + "time" + + "github.com/ClickHouse/clickhouse-go/lib/data" +) + +// Interface for Clickhouse driver +type Clickhouse interface { + Block() (*data.Block, error) + Prepare(query string) (driver.Stmt, error) + Begin() (driver.Tx, error) + Commit() error + Rollback() error + Close() error + WriteBlock(block *data.Block) error +} + +// Interface for Block allowing writes to individual columns +type ColumnWriter interface { + WriteDate(c int, v time.Time) error + WriteDateNullable(c int, v *time.Time) error + WriteDateTime(c int, v time.Time) error + WriteDateTimeNullable(c int, v *time.Time) error + WriteUInt8(c int, v uint8) error + WriteUInt8Nullable(c int, v *uint8) error + WriteUInt16(c int, v uint16) error + WriteUInt16Nullable(c int, v *uint16) error + WriteUInt32(c int, v uint32) error + WriteUInt32Nullable(c int, v *uint32) error + WriteUInt64(c int, v uint64) error + WriteUInt64Nullable(c int, v *uint64) error + WriteFloat32(c int, v float32) error + WriteFloat32Nullable(c int, v *float32) error + WriteFloat64(c int, v float64) error + WriteFloat64Nullable(c int, v *float64) error + WriteBytes(c int, v []byte) error + WriteArray(c int, v interface{}) error + WriteBytesNullable(c int, v *[]byte) error + WriteArrayNullable(c int, v *interface{}) error + WriteString(c int, v string) error + WriteStringNullable(c int, v *string) error + WriteFixedString(c int, v []byte) error + WriteFixedStringNullable(c int, v *[]byte) error +} + +func OpenDirect(dsn string) (Clickhouse, error) { + return open(dsn) +} + +func (ch *clickhouse) Block() (*data.Block, error) { + if ch.block == nil { + return nil, sql.ErrTxDone + } + return ch.block, nil +} + +func (ch *clickhouse) WriteBlock(block *data.Block) error { + if block == nil { + return sql.ErrTxDone + } + return ch.writeBlock(block, "") +} diff --git a/vendor/github.com/cloudflare/golz4/.gitignore b/vendor/github.com/cloudflare/golz4/.gitignore new file mode 100644 index 0000000000..00268614f0 --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/.gitignore @@ -0,0 +1,22 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe diff --git a/vendor/github.com/cloudflare/golz4/LICENSE b/vendor/github.com/cloudflare/golz4/LICENSE new file mode 100644 index 0000000000..1579e81a9a --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2013 CloudFlare, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + +* Neither the name of the CloudFlare, Inc. nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/cloudflare/golz4/Makefile b/vendor/github.com/cloudflare/golz4/Makefile new file mode 100644 index 0000000000..2296d80e06 --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/Makefile @@ -0,0 +1,14 @@ +GCFLAGS := +LDFLAGS := + +.PHONY: install +install: + @go install -v . + +.PHONY: test +test: + @go test -gcflags='$(GCFLAGS)' -ldflags='$(LDFLAGS)' . + +.PHONY: bench +bench: + @go test -gcflags='$(GCFLAGS)' -ldflags='$(LDFLAGS)' -bench . diff --git a/vendor/github.com/cloudflare/golz4/README.md b/vendor/github.com/cloudflare/golz4/README.md new file mode 100644 index 0000000000..e1bdb26e82 --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/README.md @@ -0,0 +1,4 @@ +golz4 +===== + +Golang interface to LZ4 compression diff --git a/vendor/github.com/cloudflare/golz4/doc.go b/vendor/github.com/cloudflare/golz4/doc.go new file mode 100644 index 0000000000..4876be870f --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/doc.go @@ -0,0 +1,4 @@ +// Package lz4 implements compression using lz4.c and lz4hc.c +// +// Copyright (c) 2013 CloudFlare, Inc. +package lz4 diff --git a/vendor/github.com/cloudflare/golz4/lz4.go b/vendor/github.com/cloudflare/golz4/lz4.go new file mode 100644 index 0000000000..f9abcb2dbc --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/lz4.go @@ -0,0 +1,55 @@ +package lz4 + +// #cgo CFLAGS: -O3 +// #include "src/lz4.h" +// #include "src/lz4.c" +import "C" + +import ( + "errors" + "fmt" + "unsafe" +) + +// p gets a char pointer to the first byte of a []byte slice +func p(in []byte) *C.char { + if len(in) == 0 { + return (*C.char)(unsafe.Pointer(nil)) + } + return (*C.char)(unsafe.Pointer(&in[0])) +} + +// clen gets the length of a []byte slice as a char * +func clen(s []byte) C.int { + return C.int(len(s)) +} + +// Uncompress with a known output size. len(out) should be equal to +// the length of the uncompressed out. +func Uncompress(in, out []byte) (error) { + if int(C.LZ4_decompress_safe(p(in), p(out), clen(in), clen(out))) < 0 { + return errors.New("Malformed compression stream") + } + + return nil +} + +// CompressBound calculates the size of the output buffer needed by +// Compress. This is based on the following macro: +// +// #define LZ4_COMPRESSBOUND(isize) +// ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16) +func CompressBound(in []byte) int { + return len(in) + ((len(in) / 255) + 16) +} + +// Compress compresses in and puts the content in out. len(out) +// should have enough space for the compressed data (use CompressBound +// to calculate). Returns the number of bytes in the out slice. +func Compress(in, out []byte) (outSize int, err error) { + outSize = int(C.LZ4_compress_limitedOutput(p(in), p(out), clen(in), clen(out))) + if outSize == 0 { + err = fmt.Errorf("insufficient space for compression") + } + return +} diff --git a/vendor/github.com/cloudflare/golz4/lz4_hc.go b/vendor/github.com/cloudflare/golz4/lz4_hc.go new file mode 100644 index 0000000000..9779352c46 --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/lz4_hc.go @@ -0,0 +1,38 @@ +package lz4 + +// #cgo CFLAGS: -O3 +// #include "src/lz4hc.h" +// #include "src/lz4hc.c" +import "C" + +import ( + "fmt" +) + +// CompressHC compresses in and puts the content in out. len(out) +// should have enough space for the compressed data (use CompressBound +// to calculate). Returns the number of bytes in the out slice. Determines +// the compression level automatically. +func CompressHC(in, out []byte) (int, error) { + // 0 automatically sets the compression level. + return CompressHCLevel(in, out, 0) +} + +// CompressHCLevel compresses in at the given compression level and puts the +// content in out. len(out) should have enough space for the compressed data +// (use CompressBound to calculate). Returns the number of bytes in the out +// slice. To automatically choose the compression level, use 0. Otherwise, use +// any value in the inclusive range 1 (worst) through 16 (best). Most +// applications will prefer CompressHC. +func CompressHCLevel(in, out []byte, level int) (outSize int, err error) { + // LZ4HC does not handle empty buffers. Pass through to Compress. + if len(in) == 0 || len(out) == 0 { + return Compress(in, out) + } + + outSize = int(C.LZ4_compressHC2_limitedOutput(p(in), p(out), clen(in), clen(out), C.int(level))) + if outSize == 0 { + err = fmt.Errorf("insufficient space for compression") + } + return +} diff --git a/vendor/github.com/cloudflare/golz4/sample.txt b/vendor/github.com/cloudflare/golz4/sample.txt new file mode 100644 index 0000000000..3bb27fb76d --- /dev/null +++ b/vendor/github.com/cloudflare/golz4/sample.txt @@ -0,0 +1,143 @@ +CANTO I + + +IN the midway of this our mortal life, +I found me in a gloomy wood, astray +Gone from the path direct: and e'en to tell +It were no easy task, how savage wild +That forest, how robust and rough its growth, +Which to remember only, my dismay +Renews, in bitterness not far from death. +Yet to discourse of what there good befell, +All else will I relate discover'd there. +How first I enter'd it I scarce can say, +Such sleepy dullness in that instant weigh'd +My senses down, when the true path I left, +But when a mountain's foot I reach'd, where clos'd +The valley, that had pierc'd my heart with dread, +I look'd aloft, and saw his shoulders broad +Already vested with that planet's beam, +Who leads all wanderers safe through every way. + +Then was a little respite to the fear, +That in my heart's recesses deep had lain, +All of that night, so pitifully pass'd: +And as a man, with difficult short breath, +Forespent with toiling, 'scap'd from sea to shore, +Turns to the perilous wide waste, and stands +At gaze; e'en so my spirit, that yet fail'd +Struggling with terror, turn'd to view the straits, +That none hath pass'd and liv'd. My weary frame +After short pause recomforted, again +I journey'd on over that lonely steep, + +The hinder foot still firmer. Scarce the ascent +Began, when, lo! a panther, nimble, light, +And cover'd with a speckled skin, appear'd, +Nor, when it saw me, vanish'd, rather strove +To check my onward going; that ofttimes +With purpose to retrace my steps I turn'd. + +The hour was morning's prime, and on his way +Aloft the sun ascended with those stars, +That with him rose, when Love divine first mov'd +Those its fair works: so that with joyous hope +All things conspir'd to fill me, the gay skin +Of that swift animal, the matin dawn +And the sweet season. Soon that joy was chas'd, +And by new dread succeeded, when in view +A lion came, 'gainst me, as it appear'd, + +With his head held aloft and hunger-mad, +That e'en the air was fear-struck. A she-wolf +Was at his heels, who in her leanness seem'd +Full of all wants, and many a land hath made +Disconsolate ere now. She with such fear +O'erwhelmed me, at the sight of her appall'd, +That of the height all hope I lost. As one, +Who with his gain elated, sees the time +When all unwares is gone, he inwardly +Mourns with heart-griping anguish; such was I, +Haunted by that fell beast, never at peace, +Who coming o'er against me, by degrees +Impell'd me where the sun in silence rests. + +While to the lower space with backward step +I fell, my ken discern'd the form one of one, +Whose voice seem'd faint through long disuse of speech. +When him in that great desert I espied, +"Have mercy on me!" cried I out aloud, +"Spirit! or living man! what e'er thou be!" + +He answer'd: "Now not man, man once I was, +And born of Lombard parents, Mantuana both +By country, when the power of Julius yet +Was scarcely firm. At Rome my life was past +Beneath the mild Augustus, in the time +Of fabled deities and false. A bard +Was I, and made Anchises' upright son +The subject of my song, who came from Troy, +When the flames prey'd on Ilium's haughty towers. +But thou, say wherefore to such perils past +Return'st thou? wherefore not this pleasant mount +Ascendest, cause and source of all delight?" +"And art thou then that Virgil, that well-spring, +From which such copious floods of eloquence +Have issued?" I with front abash'd replied. +"Glory and light of all the tuneful train! +May it avail me that I long with zeal +Have sought thy volume, and with love immense +Have conn'd it o'er. My master thou and guide! +Thou he from whom alone I have deriv'd +That style, which for its beauty into fame +Exalts me. See the beast, from whom I fled. +O save me from her, thou illustrious sage!" + +"For every vein and pulse throughout my frame +She hath made tremble." He, soon as he saw +That I was weeping, answer'd, "Thou must needs +Another way pursue, if thou wouldst 'scape +From out that savage wilderness. This beast, +At whom thou criest, her way will suffer none +To pass, and no less hindrance makes than death: +So bad and so accursed in her kind, +That never sated is her ravenous will, +Still after food more craving than before. +To many an animal in wedlock vile +She fastens, and shall yet to many more, +Until that greyhound come, who shall destroy +Her with sharp pain. He will not life support +By earth nor its base metals, but by love, +Wisdom, and virtue, and his land shall be +The land 'twixt either Feltro. In his might +Shall safety to Italia's plains arise, +For whose fair realm, Camilla, virgin pure, +Nisus, Euryalus, and Turnus fell. +He with incessant chase through every town +Shall worry, until he to hell at length +Restore her, thence by envy first let loose. +I for thy profit pond'ring now devise, +That thou mayst follow me, and I thy guide +Will lead thee hence through an eternal space, +Where thou shalt hear despairing shrieks, and see +Spirits of old tormented, who invoke +A second death; and those next view, who dwell +Content in fire, for that they hope to come, +Whene'er the time may be, among the blest, +Into whose regions if thou then desire +T' ascend, a spirit worthier then I +Must lead thee, in whose charge, when I depart, +Thou shalt be left: for that Almighty King, +Who reigns above, a rebel to his law, +Adjudges me, and therefore hath decreed, +That to his city none through me should come. +He in all parts hath sway; there rules, there holds +His citadel and throne. O happy those, +Whom there he chooses!" I to him in few: +"Bard! by that God, whom thou didst not adore, +I do beseech thee (that this ill and worse +I may escape) to lead me, where thou saidst, +That I Saint Peter's gate may view, and those +Who as thou tell'st, are in such dismal plight." + +Onward he mov'd, I close his steps pursu'd. diff --git a/vendor/github.com/paulmach/orb/CHANGELOG.md b/vendor/github.com/paulmach/orb/CHANGELOG.md deleted file mode 100644 index 5691ca1d3d..0000000000 --- a/vendor/github.com/paulmach/orb/CHANGELOG.md +++ /dev/null @@ -1,117 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -## [v0.7.1](https://github.com/paulmach/orb/compare/v0.7.0...v0.7.1) - 2022-05-16 - -No changes - -The v0.7.0 tag was updated since it initially pointed to the wrong commit. This is causing caching issues. - -## [v0.7.0](https://github.com/paulmach/orb/compare/v0.6.0...v0.7.0) - 2022-05-10 - -This tag is broken, please use v0.7.1 instead. - -### Breaking Changes - -- tilecover now returns an error (vs. panicing) on non-closed 2d geometry by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/87 - - This changes the signature of many of the methods in the [maptile/tilecover](https://github.com/paulmach/orb/tree/master/maptile/tilecover) package. - To emulate the old behavior replace: - - tiles := tilecover.Geometry(poly, zoom) - - with - - tiles, err := tilecover.Geometry(poly, zoom) - if err != nil { - panic(err) - } - -## [v0.6.0](https://github.com/paulmach/orb/compare/v0.5.0...v0.6.0) - 2022-05-04 - -### Added - -- geo: add correctly spelled LengthHaversine by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/97 -- geojson: add support for "external" json encoders/decoders by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/98 -- Add ewkb encoding/decoding support by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/88 - -## [v0.5.0](https://github.com/paulmach/orb/compare/v0.4.0...v0.5.0) - 2022-04-06 - -### Added - -- encoding/mvt: stable marshalling by [@travisgrigsby](https://github.com/travisgrigsby) in https://github.com/paulmach/orb/pull/93 -- encoding/mvt: support mvt marshal for GeometryCollection by [@dadadamarine](https://github.com/dadadamarine) in https://github.com/paulmach/orb/pull/89 - -### Fixed - -- quadtree: fix cleanup of nodes during removal by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/94 - -### Other - -- encoding/wkt: various code improvements by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/95 -- update protoscan to 0.2.1 by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/83 - -## [v0.4.0](https://github.com/paulmach/orb/compare/v0.3.0...v0.4.0) - 2021-11-11 - -### Added - -- geo: Add functions to calculate points based on distance and bearing by [@thzinc](https://github.com/thzinc) in https://github.com/paulmach/orb/pull/76 - -### Fixed - -- encoding/mvt: avoid reflect nil value by [@nicklasaven](https://github.com/nicklasaven) in https://github.com/paulmach/orb/pull/78 - -## [v0.3.0](https://github.com/paulmach/orb/compare/v0.2.2...v0.3.0) - 2021-10-16 - -### Changed - -- quadtree: sort KNearest results closest first by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/75 -- ring: require >=4 points to return true when calling Closed() by [@missinglink](https://github.com/missinglink) in https://github.com/paulmach/orb/pull/70 - -### Fixed - -- encoding/mvt: verify tile coord does not overflow for z > 20 by [@paulmach](https://github.com/paulmach) in https://github.com/paulmach/orb/pull/74 -- quadtree: Address panic-ing quadtree.Matching(…) method when finding no closest node by [@willsalz](https://github.com/willsalz) in https://github.com/paulmach/orb/pull/73 - -## [v0.2.2](https://github.com/paulmach/orb/compare/v0.2.1...v0.2.2) - 2021-06-05 - -### Fixed - -- Dependency resolution problems in some cases, issue https://github.com/paulmach/orb/issues/65, pr https://github.com/paulmach/orb/pull/66 - -## [v0.2.1](https://github.com/paulmach/orb/compare/v0.2.0...v0.2.1) - 2021-01-16 - -### Changed - -- encoding/mvt: upgrade protoscan v0.1 -> v0.2 [`ad31566`](https://github.com/paulmach/orb/commit/ad31566942027c1cd30dd341f35123fb54676599) -- encoding/mvt: remove github.com/pkg/errors as a dependency [`d2e235`](https://github.com/paulmach/orb/commit/d2e23529a295a0d973cc787ad2742cb6ccbd5306) - -## v0.2.0 - 2021-01-16 - -### Breaking Changes - -- Foreign Members in Feature Collections - - Extra attributes in a feature collection object will now be put into `featureCollection.ExtraMembers`. - Similarly, stuff in `ExtraMembers will be marshalled into the feature collection base. - The break happens if you were decoding these foreign members using something like - - ```go - type MyFeatureCollection struct { - geojson.FeatureCollection - Title string `json:"title"` - } - ``` - - **The above will no longer work** in this release and it never supported marshalling. See https://github.com/paulmach/orb/pull/56 for more details. - -- Features with nil/missing geometry will no longer return an errors - - Previously missing or invalid geometry in a feature collection would return a `ErrInvalidGeometry` error. - However missing geometry is compliant with [section 3.2](https://tools.ietf.org/html/rfc7946#section-3.2) of the spec. - See https://github.com/paulmach/orb/issues/38 and https://github.com/paulmach/orb/pull/58 for more details. - -### Changed - -- encoding/mvt: faster unmarshalling for Mapbox Vector Tiles (MVT) see https://github.com/paulmach/orb/pull/57 diff --git a/vendor/github.com/paulmach/orb/LICENSE.md b/vendor/github.com/paulmach/orb/LICENSE.md deleted file mode 100644 index 526962ad0f..0000000000 --- a/vendor/github.com/paulmach/orb/LICENSE.md +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2017 Paul Mach - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/paulmach/orb/README.md b/vendor/github.com/paulmach/orb/README.md deleted file mode 100644 index 8d0e515023..0000000000 --- a/vendor/github.com/paulmach/orb/README.md +++ /dev/null @@ -1,179 +0,0 @@ -# orb [![CI](https://github.com/paulmach/orb/workflows/CI/badge.svg)](https://github.com/paulmach/orb/actions?query=workflow%3ACI+event%3Apush) [![codecov](https://codecov.io/gh/paulmach/orb/branch/master/graph/badge.svg?token=NuuTjLVpKW)](https://codecov.io/gh/paulmach/orb) [![Go Report Card](https://goreportcard.com/badge/github.com/paulmach/orb)](https://goreportcard.com/report/github.com/paulmach/orb) [![Go Reference](https://pkg.go.dev/badge/github.com/paulmach/orb.svg)](https://pkg.go.dev/github.com/paulmach/orb) - -Package `orb` defines a set of types for working with 2d geo and planar/projected geometric data in Golang. -There are a set of sub-packages that use these types to do interesting things. -They each provider their own README with extra info. - -## Interesting features - -- **Simple types** - allow for natural operations using the `make`, `append`, `len`, `[s:e]` builtins. -- **GeoJSON** - support as part of the [`geojson`](geojson) sub-package. -- **Mapbox Vector Tile** - encoding and decoding as part of the [`encoding/mvt`](encoding/mvt) sub-package. -- **Direct to type from DB query results** - by scanning WKB data directly into types. -- **Rich set of sub-packages** - including [`clipping`](clip), [`simplifing`](simplify), [`quadtree`](quadtree) and more. - -## Type definitions - -```go -type Point [2]float64 -type MultiPoint []Point - -type LineString []Point -type MultiLineString []LineString - -type Ring LineString -type Polygon []Ring -type MultiPolygon []Polygon - -type Collection []Geometry - -type Bound struct { Min, Max Point } -``` - -Defining the types as slices allows them to be accessed in an idiomatic way -using Go's built-in functions such at `make`, `append`, `len` -and with slice notation like `[s:e]`. For example: - -```go -ls := make(orb.LineString, 0, 100) -ls = append(ls, orb.Point{1, 1}) -point := ls[0] -``` - -### Shared `Geometry` interface - -All of the base types implement the `orb.Geometry` interface defined as: - -```go -type Geometry interface { - GeoJSONType() string - Dimensions() int // e.g. 0d, 1d, 2d - Bound() Bound -} -``` - -This interface is accepted by functions in the sub-packages which then act on the -base types correctly. For example: - -```go -l := clip.Geometry(bound, geom) -``` - -will use the appropriate clipping algorithm depending on if the input is 1d or 2d, -e.g. a `orb.LineString` or a `orb.Polygon`. - -Only a few methods are defined directly on these type, for example `Clone`, `Equal`, `GeoJSONType`. -Other operation that depend on geo vs. planar contexts are defined in the respective sub-package. -For example: - -- Computing the geo distance between two point: - - ```go - p1 := orb.Point{-72.796408, -45.407131} - p2 := orb.Point{-72.688541, -45.384987} - - geo.Distance(p1, p2) - ``` - -- Compute the planar area and centroid of a polygon: - - ```go - poly := orb.Polygon{...} - centroid, area := planar.CentroidArea(poly) - ``` - -## GeoJSON - -The [geojson](geojson) sub-package implements Marshalling and Unmarshalling of GeoJSON data. -Features are defined as: - -```go -type Feature struct { - ID interface{} `json:"id,omitempty"` - Type string `json:"type"` - Geometry orb.Geometry `json:"geometry"` - Properties Properties `json:"properties"` -} -``` - -Defining the geometry as an `orb.Geometry` interface along with sub-package functions -accepting geometries allows them to work together to create easy to follow code. -For example, clipping all the geometries in a collection: - -```go -fc, err := geojson.UnmarshalFeatureCollection(data) -for _, f := range fc { - f.Geometry = clip.Geometry(bound, f.Geometry) -} -``` - -The library supports third party "encoding/json" replacements -such [github.com/json-iterator/go](https://github.com/json-iterator/go). -See the [geojson](geojson) readme for more details. - -## Mapbox Vector Tiles - -The [encoding/mvt](encoding/mvt) sub-package implements Marshalling and -Unmarshalling [MVT](https://www.mapbox.com/vector-tiles/) data. -This package uses sets of `geojson.FeatureCollection` to define the layers, -keyed by the layer name. For example: - -```go -collections := map[string]*geojson.FeatureCollection{} - -// Convert to a layers object and project to tile coordinates. -layers := mvt.NewLayers(collections) -layers.ProjectToTile(maptile.New(x, y, z)) - -// In order to be used as source for MapboxGL geometries need to be clipped -// to max allowed extent. (uncomment next line) -// layers.Clip(mvt.MapboxGLDefaultExtentBound) - -// Simplify the geometry now that it's in tile coordinate space. -layers.Simplify(simplify.DouglasPeucker(1.0)) - -// Depending on use-case remove empty geometry, those too small to be -// represented in this tile space. -// In this case lines shorter than 1, and areas smaller than 2. -layers.RemoveEmpty(1.0, 2.0) - -// encoding using the Mapbox Vector Tile protobuf encoding. -data, err := layers.Marshal() // this data is NOT gzipped. - -// Sometimes MVT data is stored and transfered gzip compressed. In that case: -data, err := layers.MarshalGzipped() -``` - -## Decoding WKB/EWKB from a database query - -Geometries are usually returned from databases in WKB or EWKB format. The [encoding/ewkb](encoding/ewkb) -sub-package offers helpers to "scan" the data into the base types directly. -For example: - -```go -db.Exec( - "INSERT INTO postgis_table (point_column) VALUES (ST_GeomFromEWKB(?))", - ewkb.Value(orb.Point{1, 2}, 4326), -) - -row := db.QueryRow("SELECT ST_AsBinary(point_column) FROM postgis_table") - -var p orb.Point -err := row.Scan(ewkb.Scanner(&p)) -``` - -For more information see the readme in the [encoding/ewkb](encoding/ewkb) package. - -## List of sub-package utilities - -- [`clip`](clip) - clipping geometry to a bounding box -- [`encoding/mvt`](encoding/mvt) - encoded and decoding from [Mapbox Vector Tiles](https://www.mapbox.com/vector-tiles/) -- [`encoding/wkb`](encoding/wkb) - well-known binary as well as helpers to decode from the database queries -- [`encoding/ewkb`](encoding/ewkb) - extended well-known binary format that includes the SRID -- [`encoding/wkt`](encoding/wkt) - well-known text encoding -- [`geojson`](geojson) - working with geojson and the types in this package -- [`maptile`](maptile) - working with mercator map tiles and quadkeys -- [`project`](project) - project geometries between geo and planar contexts -- [`quadtree`](quadtree) - quadtree implementation using the types in this package -- [`resample`](resample) - resample points in a line string geometry -- [`simplify`](simplify) - linear geometry simplifications like Douglas-Peucker diff --git a/vendor/github.com/paulmach/orb/bound.go b/vendor/github.com/paulmach/orb/bound.go deleted file mode 100644 index a0726d64e8..0000000000 --- a/vendor/github.com/paulmach/orb/bound.go +++ /dev/null @@ -1,172 +0,0 @@ -package orb - -import ( - "math" -) - -var emptyBound = Bound{Min: Point{1, 1}, Max: Point{-1, -1}} - -// A Bound represents a closed box or rectangle. -// To create a bound with two points you can do something like: -// orb.MultiPoint{p1, p2}.Bound() -type Bound struct { - Min, Max Point -} - -// GeoJSONType returns the GeoJSON type for the object. -func (b Bound) GeoJSONType() string { - return "Polygon" -} - -// Dimensions returns 2 because a Bound is a 2d object. -func (b Bound) Dimensions() int { - return 2 -} - -// ToPolygon converts the bound into a Polygon object. -func (b Bound) ToPolygon() Polygon { - return Polygon{b.ToRing()} -} - -// ToRing converts the bound into a loop defined -// by the boundary of the box. -func (b Bound) ToRing() Ring { - return Ring{ - b.Min, - Point{b.Max[0], b.Min[1]}, - b.Max, - Point{b.Min[0], b.Max[1]}, - b.Min, - } -} - -// Extend grows the bound to include the new point. -func (b Bound) Extend(point Point) Bound { - // already included, no big deal - if b.Contains(point) { - return b - } - - return Bound{ - Min: Point{ - math.Min(b.Min[0], point[0]), - math.Min(b.Min[1], point[1]), - }, - Max: Point{ - math.Max(b.Max[0], point[0]), - math.Max(b.Max[1], point[1]), - }, - } -} - -// Union extends this bound to contain the union of this and the given bound. -func (b Bound) Union(other Bound) Bound { - if other.IsEmpty() { - return b - } - - b = b.Extend(other.Min) - b = b.Extend(other.Max) - b = b.Extend(other.LeftTop()) - b = b.Extend(other.RightBottom()) - - return b -} - -// Contains determines if the point is within the bound. -// Points on the boundary are considered within. -func (b Bound) Contains(point Point) bool { - if point[1] < b.Min[1] || b.Max[1] < point[1] { - return false - } - - if point[0] < b.Min[0] || b.Max[0] < point[0] { - return false - } - - return true -} - -// Intersects determines if two bounds intersect. -// Returns true if they are touching. -func (b Bound) Intersects(bound Bound) bool { - if (b.Max[0] < bound.Min[0]) || - (b.Min[0] > bound.Max[0]) || - (b.Max[1] < bound.Min[1]) || - (b.Min[1] > bound.Max[1]) { - return false - } - - return true -} - -// Pad extends the bound in all directions by the given value. -func (b Bound) Pad(d float64) Bound { - b.Min[0] -= d - b.Min[1] -= d - - b.Max[0] += d - b.Max[1] += d - - return b -} - -// Center returns the center of the bounds by "averaging" the x and y coords. -func (b Bound) Center() Point { - return Point{ - (b.Min[0] + b.Max[0]) / 2.0, - (b.Min[1] + b.Max[1]) / 2.0, - } -} - -// Top returns the top of the bound. -func (b Bound) Top() float64 { - return b.Max[1] -} - -// Bottom returns the bottom of the bound. -func (b Bound) Bottom() float64 { - return b.Min[1] -} - -// Right returns the right of the bound. -func (b Bound) Right() float64 { - return b.Max[0] -} - -// Left returns the left of the bound. -func (b Bound) Left() float64 { - return b.Min[0] -} - -// LeftTop returns the upper left point of the bound. -func (b Bound) LeftTop() Point { - return Point{b.Left(), b.Top()} -} - -// RightBottom return the lower right point of the bound. -func (b Bound) RightBottom() Point { - return Point{b.Right(), b.Bottom()} -} - -// IsEmpty returns true if it contains zero area or if -// it's in some malformed negative state where the left point is larger than the right. -// This can be caused by padding too much negative. -func (b Bound) IsEmpty() bool { - return b.Min[0] > b.Max[0] || b.Min[1] > b.Max[1] -} - -// IsZero return true if the bound just includes just null island. -func (b Bound) IsZero() bool { - return b.Max == Point{} && b.Min == Point{} -} - -// Bound returns the the same bound. -func (b Bound) Bound() Bound { - return b -} - -// Equal returns if two bounds are equal. -func (b Bound) Equal(c Bound) bool { - return b.Min == c.Min && b.Max == c.Max -} diff --git a/vendor/github.com/paulmach/orb/clone.go b/vendor/github.com/paulmach/orb/clone.go deleted file mode 100644 index ac757b7274..0000000000 --- a/vendor/github.com/paulmach/orb/clone.go +++ /dev/null @@ -1,56 +0,0 @@ -package orb - -import ( - "fmt" -) - -// Clone will make a deep copy of the geometry. -func Clone(g Geometry) Geometry { - if g == nil { - return nil - } - - switch g := g.(type) { - case Point: - return g - case MultiPoint: - if g == nil { - return nil - } - return g.Clone() - case LineString: - if g == nil { - return nil - } - return g.Clone() - case MultiLineString: - if g == nil { - return nil - } - return g.Clone() - case Ring: - if g == nil { - return nil - } - return g.Clone() - case Polygon: - if g == nil { - return nil - } - return g.Clone() - case MultiPolygon: - if g == nil { - return nil - } - return g.Clone() - case Collection: - if g == nil { - return nil - } - return g.Clone() - case Bound: - return g - } - - panic(fmt.Sprintf("geometry type not supported: %T", g)) -} diff --git a/vendor/github.com/paulmach/orb/codecov.yml b/vendor/github.com/paulmach/orb/codecov.yml deleted file mode 100644 index 8bf5754f45..0000000000 --- a/vendor/github.com/paulmach/orb/codecov.yml +++ /dev/null @@ -1,10 +0,0 @@ -coverage: - status: - project: off - patch: off - - precision: 2 - round: down - range: "70...90" - -comment: false diff --git a/vendor/github.com/paulmach/orb/define.go b/vendor/github.com/paulmach/orb/define.go deleted file mode 100644 index a0b08f3a58..0000000000 --- a/vendor/github.com/paulmach/orb/define.go +++ /dev/null @@ -1,44 +0,0 @@ -package orb - -// EarthRadius is the radius of the earth in meters. It is used in geo distance calculations. -// To keep things consistent, this value matches WGS84 Web Mercator (EPSG:3857). -const EarthRadius = 6378137.0 // meters - -// DefaultRoundingFactor is the default rounding factor used by the Round func. -var DefaultRoundingFactor = 1e6 // 6 decimal places - -// Orientation defines the order of the points in a polygon -// or closed ring. -type Orientation int8 - -// Constants to define orientation. -// They follow the right hand rule for orientation. -const ( - // CCW stands for Counter Clock Wise - CCW Orientation = 1 - - // CW stands for Clock Wise - CW Orientation = -1 -) - -// A DistanceFunc is a function that computes the distance between two points. -type DistanceFunc func(Point, Point) float64 - -// A Projection a function that moves a point from one space to another. -type Projection func(Point) Point - -// Pointer is something that can be represented by a point. -type Pointer interface { - Point() Point -} - -// A Simplifier is something that can simplify geometry. -type Simplifier interface { - Simplify(g Geometry) Geometry - LineString(ls LineString) LineString - MultiLineString(mls MultiLineString) MultiLineString - Ring(r Ring) Ring - Polygon(p Polygon) Polygon - MultiPolygon(mp MultiPolygon) MultiPolygon - Collection(c Collection) Collection -} diff --git a/vendor/github.com/paulmach/orb/equal.go b/vendor/github.com/paulmach/orb/equal.go deleted file mode 100644 index 7cc87dd5eb..0000000000 --- a/vendor/github.com/paulmach/orb/equal.go +++ /dev/null @@ -1,51 +0,0 @@ -package orb - -import ( - "fmt" -) - -// Equal returns if the two geometrires are equal. -func Equal(g1, g2 Geometry) bool { - if g1 == nil || g2 == nil { - return g1 == g2 - } - - if g1.GeoJSONType() != g2.GeoJSONType() { - return false - } - - switch g1 := g1.(type) { - case Point: - return g1.Equal(g2.(Point)) - case MultiPoint: - return g1.Equal(g2.(MultiPoint)) - case LineString: - return g1.Equal(g2.(LineString)) - case MultiLineString: - return g1.Equal(g2.(MultiLineString)) - case Ring: - g2, ok := g2.(Ring) - if !ok { - return false - } - return g1.Equal(g2) - case Polygon: - g2, ok := g2.(Polygon) - if !ok { - return false - } - return g1.Equal(g2) - case MultiPolygon: - return g1.Equal(g2.(MultiPolygon)) - case Collection: - return g1.Equal(g2.(Collection)) - case Bound: - g2, ok := g2.(Bound) - if !ok { - return false - } - return g1.Equal(g2) - } - - panic(fmt.Sprintf("geometry type not supported: %T", g1)) -} diff --git a/vendor/github.com/paulmach/orb/geometry.go b/vendor/github.com/paulmach/orb/geometry.go deleted file mode 100644 index a15e36b7ab..0000000000 --- a/vendor/github.com/paulmach/orb/geometry.go +++ /dev/null @@ -1,146 +0,0 @@ -package orb - -// Geometry is an interface that represents the shared attributes -// of a geometry. -type Geometry interface { - GeoJSONType() string - Dimensions() int // e.g. 0d, 1d, 2d - Bound() Bound - - // requiring because sub package type switch over all possible types. - private() -} - -// compile time checks -var ( - _ Geometry = Point{} - _ Geometry = MultiPoint{} - _ Geometry = LineString{} - _ Geometry = MultiLineString{} - _ Geometry = Ring{} - _ Geometry = Polygon{} - _ Geometry = MultiPolygon{} - _ Geometry = Bound{} - - _ Geometry = Collection{} -) - -func (p Point) private() {} -func (mp MultiPoint) private() {} -func (ls LineString) private() {} -func (mls MultiLineString) private() {} -func (r Ring) private() {} -func (p Polygon) private() {} -func (mp MultiPolygon) private() {} -func (b Bound) private() {} -func (c Collection) private() {} - -// AllGeometries lists all possible types and values that a geometry -// interface can be. It should be used only for testing to verify -// functions that accept a Geometry will work in all cases. -var AllGeometries = []Geometry{ - nil, - Point{}, - MultiPoint{}, - LineString{}, - MultiLineString{}, - Ring{}, - Polygon{}, - MultiPolygon{}, - Bound{}, - Collection{}, - - // nil values - MultiPoint(nil), - LineString(nil), - MultiLineString(nil), - Ring(nil), - Polygon(nil), - MultiPolygon(nil), - Collection(nil), - - // Collection of Collection - Collection{Collection{Point{}}}, -} - -// A Collection is a collection of geometries that is also a Geometry. -type Collection []Geometry - -// GeoJSONType returns the geometry collection type. -func (c Collection) GeoJSONType() string { - return "GeometryCollection" -} - -// Dimensions returns the max of the dimensions of the collection. -func (c Collection) Dimensions() int { - max := -1 - for _, g := range c { - if d := g.Dimensions(); d > max { - max = d - } - } - - return max -} - -// Bound returns the bounding box of all the Geometries combined. -func (c Collection) Bound() Bound { - if len(c) == 0 { - return emptyBound - } - - var b Bound - start := -1 - - for i, g := range c { - if g != nil { - start = i - b = g.Bound() - break - } - } - - if start == -1 { - return emptyBound - } - - for i := start + 1; i < len(c); i++ { - if c[i] == nil { - continue - } - - b = b.Union(c[i].Bound()) - } - - return b -} - -// Equal compares two collections. Returns true if lengths are the same -// and all the sub geometries are the same and in the same order. -func (c Collection) Equal(collection Collection) bool { - if len(c) != len(collection) { - return false - } - - for i, g := range c { - if !Equal(g, collection[i]) { - return false - } - } - - return true -} - -// Clone returns a deep copy of the collection. -func (c Collection) Clone() Collection { - if c == nil { - return nil - } - - nc := make(Collection, len(c)) - for i, g := range c { - nc[i] = Clone(g) - } - - return nc -} diff --git a/vendor/github.com/paulmach/orb/line_string.go b/vendor/github.com/paulmach/orb/line_string.go deleted file mode 100644 index 6f4893928a..0000000000 --- a/vendor/github.com/paulmach/orb/line_string.go +++ /dev/null @@ -1,40 +0,0 @@ -package orb - -// LineString represents a set of points to be thought of as a polyline. -type LineString []Point - -// GeoJSONType returns the GeoJSON type for the object. -func (ls LineString) GeoJSONType() string { - return "LineString" -} - -// Dimensions returns 1 because a LineString is a 1d object. -func (ls LineString) Dimensions() int { - return 1 -} - -// Reverse will reverse the line string. -// This is done inplace, ie. it modifies the original data. -func (ls LineString) Reverse() { - l := len(ls) - 1 - for i := 0; i <= l/2; i++ { - ls[i], ls[l-i] = ls[l-i], ls[i] - } -} - -// Bound returns a rect around the line string. Uses rectangular coordinates. -func (ls LineString) Bound() Bound { - return MultiPoint(ls).Bound() -} - -// Equal compares two line strings. Returns true if lengths are the same -// and all points are Equal. -func (ls LineString) Equal(lineString LineString) bool { - return MultiPoint(ls).Equal(MultiPoint(lineString)) -} - -// Clone returns a new copy of the line string. -func (ls LineString) Clone() LineString { - ps := MultiPoint(ls) - return LineString(ps.Clone()) -} diff --git a/vendor/github.com/paulmach/orb/multi_line_string.go b/vendor/github.com/paulmach/orb/multi_line_string.go deleted file mode 100644 index 2b67f20c1a..0000000000 --- a/vendor/github.com/paulmach/orb/multi_line_string.go +++ /dev/null @@ -1,58 +0,0 @@ -package orb - -// MultiLineString is a set of polylines. -type MultiLineString []LineString - -// GeoJSONType returns the GeoJSON type for the object. -func (mls MultiLineString) GeoJSONType() string { - return "MultiLineString" -} - -// Dimensions returns 1 because a MultiLineString is a 2d object. -func (mls MultiLineString) Dimensions() int { - return 1 -} - -// Bound returns a bound around all the line strings. -func (mls MultiLineString) Bound() Bound { - if len(mls) == 0 { - return emptyBound - } - - bound := mls[0].Bound() - for i := 1; i < len(mls); i++ { - bound = bound.Union(mls[i].Bound()) - } - - return bound -} - -// Equal compares two multi line strings. Returns true if lengths are the same -// and all points are Equal. -func (mls MultiLineString) Equal(multiLineString MultiLineString) bool { - if len(mls) != len(multiLineString) { - return false - } - - for i, ls := range mls { - if !ls.Equal(multiLineString[i]) { - return false - } - } - - return true -} - -// Clone returns a new deep copy of the multi line string. -func (mls MultiLineString) Clone() MultiLineString { - if mls == nil { - return nil - } - - nmls := make(MultiLineString, 0, len(mls)) - for _, ls := range mls { - nmls = append(nmls, ls.Clone()) - } - - return nmls -} diff --git a/vendor/github.com/paulmach/orb/multi_point.go b/vendor/github.com/paulmach/orb/multi_point.go deleted file mode 100644 index cee955c1a2..0000000000 --- a/vendor/github.com/paulmach/orb/multi_point.go +++ /dev/null @@ -1,56 +0,0 @@ -package orb - -// A MultiPoint represents a set of points in the 2D Eucledian or Cartesian plane. -type MultiPoint []Point - -// GeoJSONType returns the GeoJSON type for the object. -func (mp MultiPoint) GeoJSONType() string { - return "MultiPoint" -} - -// Dimensions returns 0 because a MultiPoint is a 0d object. -func (mp MultiPoint) Dimensions() int { - return 0 -} - -// Clone returns a new copy of the points. -func (mp MultiPoint) Clone() MultiPoint { - if mp == nil { - return nil - } - - points := make([]Point, len(mp)) - copy(points, mp) - - return MultiPoint(points) -} - -// Bound returns a bound around the points. Uses rectangular coordinates. -func (mp MultiPoint) Bound() Bound { - if len(mp) == 0 { - return emptyBound - } - - b := Bound{mp[0], mp[0]} - for _, p := range mp { - b = b.Extend(p) - } - - return b -} - -// Equal compares two MultiPoint objects. Returns true if lengths are the same -// and all points are Equal, and in the same order. -func (mp MultiPoint) Equal(multiPoint MultiPoint) bool { - if len(mp) != len(multiPoint) { - return false - } - - for i := range mp { - if !mp[i].Equal(multiPoint[i]) { - return false - } - } - - return true -} diff --git a/vendor/github.com/paulmach/orb/multi_polygon.go b/vendor/github.com/paulmach/orb/multi_polygon.go deleted file mode 100644 index 938a9a9e34..0000000000 --- a/vendor/github.com/paulmach/orb/multi_polygon.go +++ /dev/null @@ -1,56 +0,0 @@ -package orb - -// MultiPolygon is a set of polygons. -type MultiPolygon []Polygon - -// GeoJSONType returns the GeoJSON type for the object. -func (mp MultiPolygon) GeoJSONType() string { - return "MultiPolygon" -} - -// Dimensions returns 2 because a MultiPolygon is a 2d object. -func (mp MultiPolygon) Dimensions() int { - return 2 -} - -// Bound returns a bound around the multi-polygon. -func (mp MultiPolygon) Bound() Bound { - if len(mp) == 0 { - return emptyBound - } - bound := mp[0].Bound() - for i := 1; i < len(mp); i++ { - bound = bound.Union(mp[i].Bound()) - } - - return bound -} - -// Equal compares two multi-polygons. -func (mp MultiPolygon) Equal(multiPolygon MultiPolygon) bool { - if len(mp) != len(multiPolygon) { - return false - } - - for i, p := range mp { - if !p.Equal(multiPolygon[i]) { - return false - } - } - - return true -} - -// Clone returns a new deep copy of the multi-polygon. -func (mp MultiPolygon) Clone() MultiPolygon { - if mp == nil { - return nil - } - - nmp := make(MultiPolygon, 0, len(mp)) - for _, p := range mp { - nmp = append(nmp, p.Clone()) - } - - return nmp -} diff --git a/vendor/github.com/paulmach/orb/point.go b/vendor/github.com/paulmach/orb/point.go deleted file mode 100644 index c459c35d91..0000000000 --- a/vendor/github.com/paulmach/orb/point.go +++ /dev/null @@ -1,51 +0,0 @@ -package orb - -// A Point is a Lon/Lat 2d point. -type Point [2]float64 - -var _ Pointer = Point{} - -// GeoJSONType returns the GeoJSON type for the object. -func (p Point) GeoJSONType() string { - return "Point" -} - -// Dimensions returns 0 because a point is a 0d object. -func (p Point) Dimensions() int { - return 0 -} - -// Bound returns a single point bound of the point. -func (p Point) Bound() Bound { - return Bound{p, p} -} - -// Point returns itself so it implements the Pointer interface. -func (p Point) Point() Point { - return p -} - -// Y returns the vertical coordinate of the point. -func (p Point) Y() float64 { - return p[1] -} - -// X returns the horizontal coordinate of the point. -func (p Point) X() float64 { - return p[0] -} - -// Lat returns the vertical, latitude coordinate of the point. -func (p Point) Lat() float64 { - return p[1] -} - -// Lon returns the horizontal, longitude coordinate of the point. -func (p Point) Lon() float64 { - return p[0] -} - -// Equal checks if the point represents the same point or vector. -func (p Point) Equal(point Point) bool { - return p[0] == point[0] && p[1] == point[1] -} diff --git a/vendor/github.com/paulmach/orb/polygon.go b/vendor/github.com/paulmach/orb/polygon.go deleted file mode 100644 index b3e7d291e4..0000000000 --- a/vendor/github.com/paulmach/orb/polygon.go +++ /dev/null @@ -1,55 +0,0 @@ -package orb - -// Polygon is a closed area. The first LineString is the outer ring. -// The others are the holes. Each LineString is expected to be closed -// ie. the first point matches the last. -type Polygon []Ring - -// GeoJSONType returns the GeoJSON type for the object. -func (p Polygon) GeoJSONType() string { - return "Polygon" -} - -// Dimensions returns 2 because a Polygon is a 2d object. -func (p Polygon) Dimensions() int { - return 2 -} - -// Bound returns a bound around the polygon. -func (p Polygon) Bound() Bound { - if len(p) == 0 { - return emptyBound - } - return p[0].Bound() -} - -// Equal compares two polygons. Returns true if lengths are the same -// and all points are Equal. -func (p Polygon) Equal(polygon Polygon) bool { - if len(p) != len(polygon) { - return false - } - - for i := range p { - if !p[i].Equal(polygon[i]) { - return false - } - } - - return true -} - -// Clone returns a new deep copy of the polygon. -// All of the rings are also cloned. -func (p Polygon) Clone() Polygon { - if p == nil { - return p - } - - np := make(Polygon, 0, len(p)) - for _, r := range p { - np = append(np, r.Clone()) - } - - return np -} diff --git a/vendor/github.com/paulmach/orb/ring.go b/vendor/github.com/paulmach/orb/ring.go deleted file mode 100644 index 5fe88aca26..0000000000 --- a/vendor/github.com/paulmach/orb/ring.go +++ /dev/null @@ -1,75 +0,0 @@ -package orb - -// Ring represents a set of ring on the earth. -type Ring LineString - -// GeoJSONType returns the GeoJSON type for the object. -func (r Ring) GeoJSONType() string { - return "Polygon" -} - -// Dimensions returns 2 because a Ring is a 2d object. -func (r Ring) Dimensions() int { - return 2 -} - -// Closed will return true if the ring is a real ring. -// ie. 4+ points and the first and last points match. -// NOTE: this will not check for self-intersection. -func (r Ring) Closed() bool { - return (len(r) >= 4) && (r[0] == r[len(r)-1]) -} - -// Reverse changes the direction of the ring. -// This is done inplace, ie. it modifies the original data. -func (r Ring) Reverse() { - LineString(r).Reverse() -} - -// Bound returns a rect around the ring. Uses rectangular coordinates. -func (r Ring) Bound() Bound { - return MultiPoint(r).Bound() -} - -// Orientation returns 1 if the the ring is in couter-clockwise order, -// return -1 if the ring is the clockwise order and 0 if the ring is -// degenerate and had no area. -func (r Ring) Orientation() Orientation { - area := 0.0 - - // This is a fast planar area computation, which is okay for this use. - // implicitly move everything to near the origin to help with roundoff - offsetX := r[0][0] - offsetY := r[0][1] - for i := 1; i < len(r)-1; i++ { - area += (r[i][0]-offsetX)*(r[i+1][1]-offsetY) - - (r[i+1][0]-offsetX)*(r[i][1]-offsetY) - } - - if area > 0 { - return CCW - } - - if area < 0 { - return CW - } - - // degenerate case, no area - return 0 -} - -// Equal compares two rings. Returns true if lengths are the same -// and all points are Equal. -func (r Ring) Equal(ring Ring) bool { - return MultiPoint(r).Equal(MultiPoint(ring)) -} - -// Clone returns a new copy of the ring. -func (r Ring) Clone() Ring { - if r == nil { - return nil - } - - ps := MultiPoint(r) - return Ring(ps.Clone()) -} diff --git a/vendor/github.com/paulmach/orb/round.go b/vendor/github.com/paulmach/orb/round.go deleted file mode 100644 index b6c7799389..0000000000 --- a/vendor/github.com/paulmach/orb/round.go +++ /dev/null @@ -1,100 +0,0 @@ -package orb - -import ( - "fmt" - "math" -) - -// Round will round all the coordinates of the geometry to the given factor. -// The default is 6 decimal places. -func Round(g Geometry, factor ...int) Geometry { - if g == nil { - return nil - } - - f := float64(DefaultRoundingFactor) - if len(factor) > 0 { - f = float64(factor[0]) - } - - switch g := g.(type) { - case Point: - return Point{ - math.Round(g[0]*f) / f, - math.Round(g[1]*f) / f, - } - case MultiPoint: - if g == nil { - return nil - } - roundPoints([]Point(g), f) - return g - case LineString: - if g == nil { - return nil - } - roundPoints([]Point(g), f) - return g - case MultiLineString: - if g == nil { - return nil - } - for _, ls := range g { - roundPoints([]Point(ls), f) - } - return g - case Ring: - if g == nil { - return nil - } - roundPoints([]Point(g), f) - return g - case Polygon: - if g == nil { - return nil - } - for _, r := range g { - roundPoints([]Point(r), f) - } - return g - case MultiPolygon: - if g == nil { - return nil - } - for _, p := range g { - for _, r := range p { - roundPoints([]Point(r), f) - } - } - return g - case Collection: - if g == nil { - return nil - } - - for i := range g { - g[i] = Round(g[i], int(f)) - } - return g - case Bound: - return Bound{ - Min: Point{ - math.Round(g.Min[0]*f) / f, - math.Round(g.Min[1]*f) / f, - }, - Max: Point{ - math.Round(g.Max[0]*f) / f, - math.Round(g.Max[1]*f) / f, - }, - } - } - - panic(fmt.Sprintf("geometry type not supported: %T", g)) -} - -func roundPoints(ps []Point, f float64) { - for i := range ps { - ps[i][0] = math.Round(ps[i][0]*f) / f - ps[i][1] = math.Round(ps[i][1]*f) / f - } -} diff --git a/vendor/github.com/shopspring/decimal/.gitignore b/vendor/github.com/shopspring/decimal/.gitignore deleted file mode 100644 index ff36b987f0..0000000000 --- a/vendor/github.com/shopspring/decimal/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.git -*.swp - -# IntelliJ -.idea/ -*.iml - -# VS code -*.code-workspace diff --git a/vendor/github.com/shopspring/decimal/.travis.yml b/vendor/github.com/shopspring/decimal/.travis.yml deleted file mode 100644 index 6326d40f0e..0000000000 --- a/vendor/github.com/shopspring/decimal/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: go - -arch: - - amd64 - - ppc64le - -go: - - 1.7.x - - 1.14.x - - 1.15.x - - 1.16.x - - 1.17.x - - tip - -install: - - go build . - -script: - - go test -v diff --git a/vendor/github.com/shopspring/decimal/CHANGELOG.md b/vendor/github.com/shopspring/decimal/CHANGELOG.md deleted file mode 100644 index aea61154b8..0000000000 --- a/vendor/github.com/shopspring/decimal/CHANGELOG.md +++ /dev/null @@ -1,49 +0,0 @@ -## Decimal v1.3.1 - -#### ENHANCEMENTS -- Reduce memory allocation in case of initialization from big.Int [#252](https://github.com/shopspring/decimal/pull/252) - -#### BUGFIXES -- Fix binary marshalling of decimal zero value [#253](https://github.com/shopspring/decimal/pull/253) - -## Decimal v1.3.0 - -#### FEATURES -- Add NewFromFormattedString initializer [#184](https://github.com/shopspring/decimal/pull/184) -- Add NewNullDecimal initializer [#234](https://github.com/shopspring/decimal/pull/234) -- Add implementation of natural exponent function (Taylor, Hull-Abraham) [#229](https://github.com/shopspring/decimal/pull/229) -- Add RoundUp, RoundDown, RoundCeil, RoundFloor methods [#196](https://github.com/shopspring/decimal/pull/196) [#202](https://github.com/shopspring/decimal/pull/202) [#220](https://github.com/shopspring/decimal/pull/220) -- Add XML support for NullDecimal [#192](https://github.com/shopspring/decimal/pull/192) -- Add IsInteger method [#179](https://github.com/shopspring/decimal/pull/179) -- Add Copy helper method [#123](https://github.com/shopspring/decimal/pull/123) -- Add InexactFloat64 helper method [#205](https://github.com/shopspring/decimal/pull/205) -- Add CoefficientInt64 helper method [#244](https://github.com/shopspring/decimal/pull/244) - -#### ENHANCEMENTS -- Performance optimization of NewFromString init method [#198](https://github.com/shopspring/decimal/pull/198) -- Performance optimization of Abs and Round methods [#240](https://github.com/shopspring/decimal/pull/240) -- Additional tests (CI) for ppc64le architecture [#188](https://github.com/shopspring/decimal/pull/188) - -#### BUGFIXES -- Fix rounding in FormatFloat fallback path (roundShortest method, fix taken from Go main repository) [#161](https://github.com/shopspring/decimal/pull/161) -- Add slice range checks to UnmarshalBinary method [#232](https://github.com/shopspring/decimal/pull/232) - -## Decimal v1.2.0 - -#### BREAKING -- Drop support for Go version older than 1.7 [#172](https://github.com/shopspring/decimal/pull/172) - -#### FEATURES -- Add NewFromInt and NewFromInt32 initializers [#72](https://github.com/shopspring/decimal/pull/72) -- Add support for Go modules [#157](https://github.com/shopspring/decimal/pull/157) -- Add BigInt, BigFloat helper methods [#171](https://github.com/shopspring/decimal/pull/171) - -#### ENHANCEMENTS -- Memory usage optimization [#160](https://github.com/shopspring/decimal/pull/160) -- Updated travis CI golang versions [#156](https://github.com/shopspring/decimal/pull/156) -- Update documentation [#173](https://github.com/shopspring/decimal/pull/173) -- Improve code quality [#174](https://github.com/shopspring/decimal/pull/174) - -#### BUGFIXES -- Revert remove insignificant digits [#159](https://github.com/shopspring/decimal/pull/159) -- Remove 15 interval for RoundCash [#166](https://github.com/shopspring/decimal/pull/166) diff --git a/vendor/github.com/shopspring/decimal/LICENSE b/vendor/github.com/shopspring/decimal/LICENSE deleted file mode 100644 index ad2148aaf9..0000000000 --- a/vendor/github.com/shopspring/decimal/LICENSE +++ /dev/null @@ -1,45 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Spring, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -- Based on https://github.com/oguzbilgic/fpd, which has the following license: -""" -The MIT License (MIT) - -Copyright (c) 2013 Oguz Bilgic - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -""" diff --git a/vendor/github.com/shopspring/decimal/README.md b/vendor/github.com/shopspring/decimal/README.md deleted file mode 100644 index 2e35df068e..0000000000 --- a/vendor/github.com/shopspring/decimal/README.md +++ /dev/null @@ -1,130 +0,0 @@ -# decimal - -[![Build Status](https://app.travis-ci.com/shopspring/decimal.svg?branch=master)](https://app.travis-ci.com/shopspring/decimal) [![GoDoc](https://godoc.org/github.com/shopspring/decimal?status.svg)](https://godoc.org/github.com/shopspring/decimal) [![Go Report Card](https://goreportcard.com/badge/github.com/shopspring/decimal)](https://goreportcard.com/report/github.com/shopspring/decimal) - -Arbitrary-precision fixed-point decimal numbers in go. - -_Note:_ Decimal library can "only" represent numbers with a maximum of 2^31 digits after the decimal point. - -## Features - - * The zero-value is 0, and is safe to use without initialization - * Addition, subtraction, multiplication with no loss of precision - * Division with specified precision - * Database/sql serialization/deserialization - * JSON and XML serialization/deserialization - -## Install - -Run `go get github.com/shopspring/decimal` - -## Requirements - -Decimal library requires Go version `>=1.7` - -## Usage - -```go -package main - -import ( - "fmt" - "github.com/shopspring/decimal" -) - -func main() { - price, err := decimal.NewFromString("136.02") - if err != nil { - panic(err) - } - - quantity := decimal.NewFromInt(3) - - fee, _ := decimal.NewFromString(".035") - taxRate, _ := decimal.NewFromString(".08875") - - subtotal := price.Mul(quantity) - - preTax := subtotal.Mul(fee.Add(decimal.NewFromFloat(1))) - - total := preTax.Mul(taxRate.Add(decimal.NewFromFloat(1))) - - fmt.Println("Subtotal:", subtotal) // Subtotal: 408.06 - fmt.Println("Pre-tax:", preTax) // Pre-tax: 422.3421 - fmt.Println("Taxes:", total.Sub(preTax)) // Taxes: 37.482861375 - fmt.Println("Total:", total) // Total: 459.824961375 - fmt.Println("Tax rate:", total.Sub(preTax).Div(preTax)) // Tax rate: 0.08875 -} -``` - -## Documentation - -http://godoc.org/github.com/shopspring/decimal - -## Production Usage - -* [Spring](https://shopspring.com/), since August 14, 2014. -* If you are using this in production, please let us know! - -## FAQ - -#### Why don't you just use float64? - -Because float64 (or any binary floating point type, actually) can't represent -numbers such as `0.1` exactly. - -Consider this code: http://play.golang.org/p/TQBd4yJe6B You might expect that -it prints out `10`, but it actually prints `9.999999999999831`. Over time, -these small errors can really add up! - -#### Why don't you just use big.Rat? - -big.Rat is fine for representing rational numbers, but Decimal is better for -representing money. Why? Here's a (contrived) example: - -Let's say you use big.Rat, and you have two numbers, x and y, both -representing 1/3, and you have `z = 1 - x - y = 1/3`. If you print each one -out, the string output has to stop somewhere (let's say it stops at 3 decimal -digits, for simplicity), so you'll get 0.333, 0.333, and 0.333. But where did -the other 0.001 go? - -Here's the above example as code: http://play.golang.org/p/lCZZs0w9KE - -With Decimal, the strings being printed out represent the number exactly. So, -if you have `x = y = 1/3` (with precision 3), they will actually be equal to -0.333, and when you do `z = 1 - x - y`, `z` will be equal to .334. No money is -unaccounted for! - -You still have to be careful. If you want to split a number `N` 3 ways, you -can't just send `N/3` to three different people. You have to pick one to send -`N - (2/3*N)` to. That person will receive the fraction of a penny remainder. - -But, it is much easier to be careful with Decimal than with big.Rat. - -#### Why isn't the API similar to big.Int's? - -big.Int's API is built to reduce the number of memory allocations for maximal -performance. This makes sense for its use-case, but the trade-off is that the -API is awkward and easy to misuse. - -For example, to add two big.Ints, you do: `z := new(big.Int).Add(x, y)`. A -developer unfamiliar with this API might try to do `z := a.Add(a, b)`. This -modifies `a` and sets `z` as an alias for `a`, which they might not expect. It -also modifies any other aliases to `a`. - -Here's an example of the subtle bugs you can introduce with big.Int's API: -https://play.golang.org/p/x2R_78pa8r - -In contrast, it's difficult to make such mistakes with decimal. Decimals -behave like other go numbers types: even though `a = b` will not deep copy -`b` into `a`, it is impossible to modify a Decimal, since all Decimal methods -return new Decimals and do not modify the originals. The downside is that -this causes extra allocations, so Decimal is less performant. My assumption -is that if you're using Decimals, you probably care more about correctness -than performance. - -## License - -The MIT License (MIT) - -This is a heavily modified fork of [fpd.Decimal](https://github.com/oguzbilgic/fpd), which was also released under the MIT License. diff --git a/vendor/github.com/shopspring/decimal/decimal-go.go b/vendor/github.com/shopspring/decimal/decimal-go.go deleted file mode 100644 index 9958d69020..0000000000 --- a/vendor/github.com/shopspring/decimal/decimal-go.go +++ /dev/null @@ -1,415 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Multiprecision decimal numbers. -// For floating-point formatting only; not general purpose. -// Only operations are assign and (binary) left/right shift. -// Can do binary floating point in multiprecision decimal precisely -// because 2 divides 10; cannot do decimal floating point -// in multiprecision binary precisely. - -package decimal - -type decimal struct { - d [800]byte // digits, big-endian representation - nd int // number of digits used - dp int // decimal point - neg bool // negative flag - trunc bool // discarded nonzero digits beyond d[:nd] -} - -func (a *decimal) String() string { - n := 10 + a.nd - if a.dp > 0 { - n += a.dp - } - if a.dp < 0 { - n += -a.dp - } - - buf := make([]byte, n) - w := 0 - switch { - case a.nd == 0: - return "0" - - case a.dp <= 0: - // zeros fill space between decimal point and digits - buf[w] = '0' - w++ - buf[w] = '.' - w++ - w += digitZero(buf[w : w+-a.dp]) - w += copy(buf[w:], a.d[0:a.nd]) - - case a.dp < a.nd: - // decimal point in middle of digits - w += copy(buf[w:], a.d[0:a.dp]) - buf[w] = '.' - w++ - w += copy(buf[w:], a.d[a.dp:a.nd]) - - default: - // zeros fill space between digits and decimal point - w += copy(buf[w:], a.d[0:a.nd]) - w += digitZero(buf[w : w+a.dp-a.nd]) - } - return string(buf[0:w]) -} - -func digitZero(dst []byte) int { - for i := range dst { - dst[i] = '0' - } - return len(dst) -} - -// trim trailing zeros from number. -// (They are meaningless; the decimal point is tracked -// independent of the number of digits.) -func trim(a *decimal) { - for a.nd > 0 && a.d[a.nd-1] == '0' { - a.nd-- - } - if a.nd == 0 { - a.dp = 0 - } -} - -// Assign v to a. -func (a *decimal) Assign(v uint64) { - var buf [24]byte - - // Write reversed decimal in buf. - n := 0 - for v > 0 { - v1 := v / 10 - v -= 10 * v1 - buf[n] = byte(v + '0') - n++ - v = v1 - } - - // Reverse again to produce forward decimal in a.d. - a.nd = 0 - for n--; n >= 0; n-- { - a.d[a.nd] = buf[n] - a.nd++ - } - a.dp = a.nd - trim(a) -} - -// Maximum shift that we can do in one pass without overflow. -// A uint has 32 or 64 bits, and we have to be able to accommodate 9<> 63) -const maxShift = uintSize - 4 - -// Binary shift right (/ 2) by k bits. k <= maxShift to avoid overflow. -func rightShift(a *decimal, k uint) { - r := 0 // read pointer - w := 0 // write pointer - - // Pick up enough leading digits to cover first shift. - var n uint - for ; n>>k == 0; r++ { - if r >= a.nd { - if n == 0 { - // a == 0; shouldn't get here, but handle anyway. - a.nd = 0 - return - } - for n>>k == 0 { - n = n * 10 - r++ - } - break - } - c := uint(a.d[r]) - n = n*10 + c - '0' - } - a.dp -= r - 1 - - var mask uint = (1 << k) - 1 - - // Pick up a digit, put down a digit. - for ; r < a.nd; r++ { - c := uint(a.d[r]) - dig := n >> k - n &= mask - a.d[w] = byte(dig + '0') - w++ - n = n*10 + c - '0' - } - - // Put down extra digits. - for n > 0 { - dig := n >> k - n &= mask - if w < len(a.d) { - a.d[w] = byte(dig + '0') - w++ - } else if dig > 0 { - a.trunc = true - } - n = n * 10 - } - - a.nd = w - trim(a) -} - -// Cheat sheet for left shift: table indexed by shift count giving -// number of new digits that will be introduced by that shift. -// -// For example, leftcheats[4] = {2, "625"}. That means that -// if we are shifting by 4 (multiplying by 16), it will add 2 digits -// when the string prefix is "625" through "999", and one fewer digit -// if the string prefix is "000" through "624". -// -// Credit for this trick goes to Ken. - -type leftCheat struct { - delta int // number of new digits - cutoff string // minus one digit if original < a. -} - -var leftcheats = []leftCheat{ - // Leading digits of 1/2^i = 5^i. - // 5^23 is not an exact 64-bit floating point number, - // so have to use bc for the math. - // Go up to 60 to be large enough for 32bit and 64bit platforms. - /* - seq 60 | sed 's/^/5^/' | bc | - awk 'BEGIN{ print "\t{ 0, \"\" }," } - { - log2 = log(2)/log(10) - printf("\t{ %d, \"%s\" },\t// * %d\n", - int(log2*NR+1), $0, 2**NR) - }' - */ - {0, ""}, - {1, "5"}, // * 2 - {1, "25"}, // * 4 - {1, "125"}, // * 8 - {2, "625"}, // * 16 - {2, "3125"}, // * 32 - {2, "15625"}, // * 64 - {3, "78125"}, // * 128 - {3, "390625"}, // * 256 - {3, "1953125"}, // * 512 - {4, "9765625"}, // * 1024 - {4, "48828125"}, // * 2048 - {4, "244140625"}, // * 4096 - {4, "1220703125"}, // * 8192 - {5, "6103515625"}, // * 16384 - {5, "30517578125"}, // * 32768 - {5, "152587890625"}, // * 65536 - {6, "762939453125"}, // * 131072 - {6, "3814697265625"}, // * 262144 - {6, "19073486328125"}, // * 524288 - {7, "95367431640625"}, // * 1048576 - {7, "476837158203125"}, // * 2097152 - {7, "2384185791015625"}, // * 4194304 - {7, "11920928955078125"}, // * 8388608 - {8, "59604644775390625"}, // * 16777216 - {8, "298023223876953125"}, // * 33554432 - {8, "1490116119384765625"}, // * 67108864 - {9, "7450580596923828125"}, // * 134217728 - {9, "37252902984619140625"}, // * 268435456 - {9, "186264514923095703125"}, // * 536870912 - {10, "931322574615478515625"}, // * 1073741824 - {10, "4656612873077392578125"}, // * 2147483648 - {10, "23283064365386962890625"}, // * 4294967296 - {10, "116415321826934814453125"}, // * 8589934592 - {11, "582076609134674072265625"}, // * 17179869184 - {11, "2910383045673370361328125"}, // * 34359738368 - {11, "14551915228366851806640625"}, // * 68719476736 - {12, "72759576141834259033203125"}, // * 137438953472 - {12, "363797880709171295166015625"}, // * 274877906944 - {12, "1818989403545856475830078125"}, // * 549755813888 - {13, "9094947017729282379150390625"}, // * 1099511627776 - {13, "45474735088646411895751953125"}, // * 2199023255552 - {13, "227373675443232059478759765625"}, // * 4398046511104 - {13, "1136868377216160297393798828125"}, // * 8796093022208 - {14, "5684341886080801486968994140625"}, // * 17592186044416 - {14, "28421709430404007434844970703125"}, // * 35184372088832 - {14, "142108547152020037174224853515625"}, // * 70368744177664 - {15, "710542735760100185871124267578125"}, // * 140737488355328 - {15, "3552713678800500929355621337890625"}, // * 281474976710656 - {15, "17763568394002504646778106689453125"}, // * 562949953421312 - {16, "88817841970012523233890533447265625"}, // * 1125899906842624 - {16, "444089209850062616169452667236328125"}, // * 2251799813685248 - {16, "2220446049250313080847263336181640625"}, // * 4503599627370496 - {16, "11102230246251565404236316680908203125"}, // * 9007199254740992 - {17, "55511151231257827021181583404541015625"}, // * 18014398509481984 - {17, "277555756156289135105907917022705078125"}, // * 36028797018963968 - {17, "1387778780781445675529539585113525390625"}, // * 72057594037927936 - {18, "6938893903907228377647697925567626953125"}, // * 144115188075855872 - {18, "34694469519536141888238489627838134765625"}, // * 288230376151711744 - {18, "173472347597680709441192448139190673828125"}, // * 576460752303423488 - {19, "867361737988403547205962240695953369140625"}, // * 1152921504606846976 -} - -// Is the leading prefix of b lexicographically less than s? -func prefixIsLessThan(b []byte, s string) bool { - for i := 0; i < len(s); i++ { - if i >= len(b) { - return true - } - if b[i] != s[i] { - return b[i] < s[i] - } - } - return false -} - -// Binary shift left (* 2) by k bits. k <= maxShift to avoid overflow. -func leftShift(a *decimal, k uint) { - delta := leftcheats[k].delta - if prefixIsLessThan(a.d[0:a.nd], leftcheats[k].cutoff) { - delta-- - } - - r := a.nd // read index - w := a.nd + delta // write index - - // Pick up a digit, put down a digit. - var n uint - for r--; r >= 0; r-- { - n += (uint(a.d[r]) - '0') << k - quo := n / 10 - rem := n - 10*quo - w-- - if w < len(a.d) { - a.d[w] = byte(rem + '0') - } else if rem != 0 { - a.trunc = true - } - n = quo - } - - // Put down extra digits. - for n > 0 { - quo := n / 10 - rem := n - 10*quo - w-- - if w < len(a.d) { - a.d[w] = byte(rem + '0') - } else if rem != 0 { - a.trunc = true - } - n = quo - } - - a.nd += delta - if a.nd >= len(a.d) { - a.nd = len(a.d) - } - a.dp += delta - trim(a) -} - -// Binary shift left (k > 0) or right (k < 0). -func (a *decimal) Shift(k int) { - switch { - case a.nd == 0: - // nothing to do: a == 0 - case k > 0: - for k > maxShift { - leftShift(a, maxShift) - k -= maxShift - } - leftShift(a, uint(k)) - case k < 0: - for k < -maxShift { - rightShift(a, maxShift) - k += maxShift - } - rightShift(a, uint(-k)) - } -} - -// If we chop a at nd digits, should we round up? -func shouldRoundUp(a *decimal, nd int) bool { - if nd < 0 || nd >= a.nd { - return false - } - if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even - // if we truncated, a little higher than what's recorded - always round up - if a.trunc { - return true - } - return nd > 0 && (a.d[nd-1]-'0')%2 != 0 - } - // not halfway - digit tells all - return a.d[nd] >= '5' -} - -// Round a to nd digits (or fewer). -// If nd is zero, it means we're rounding -// just to the left of the digits, as in -// 0.09 -> 0.1. -func (a *decimal) Round(nd int) { - if nd < 0 || nd >= a.nd { - return - } - if shouldRoundUp(a, nd) { - a.RoundUp(nd) - } else { - a.RoundDown(nd) - } -} - -// Round a down to nd digits (or fewer). -func (a *decimal) RoundDown(nd int) { - if nd < 0 || nd >= a.nd { - return - } - a.nd = nd - trim(a) -} - -// Round a up to nd digits (or fewer). -func (a *decimal) RoundUp(nd int) { - if nd < 0 || nd >= a.nd { - return - } - - // round up - for i := nd - 1; i >= 0; i-- { - c := a.d[i] - if c < '9' { // can stop after this digit - a.d[i]++ - a.nd = i + 1 - return - } - } - - // Number is all 9s. - // Change to single 1 with adjusted decimal point. - a.d[0] = '1' - a.nd = 1 - a.dp++ -} - -// Extract integer part, rounded appropriately. -// No guarantees about overflow. -func (a *decimal) RoundedInteger() uint64 { - if a.dp > 20 { - return 0xFFFFFFFFFFFFFFFF - } - var i int - n := uint64(0) - for i = 0; i < a.dp && i < a.nd; i++ { - n = n*10 + uint64(a.d[i]-'0') - } - for ; i < a.dp; i++ { - n *= 10 - } - if shouldRoundUp(a, a.dp) { - n++ - } - return n -} diff --git a/vendor/github.com/shopspring/decimal/decimal.go b/vendor/github.com/shopspring/decimal/decimal.go deleted file mode 100644 index 84405ec1cf..0000000000 --- a/vendor/github.com/shopspring/decimal/decimal.go +++ /dev/null @@ -1,1904 +0,0 @@ -// Package decimal implements an arbitrary precision fixed-point decimal. -// -// The zero-value of a Decimal is 0, as you would expect. -// -// The best way to create a new Decimal is to use decimal.NewFromString, ex: -// -// n, err := decimal.NewFromString("-123.4567") -// n.String() // output: "-123.4567" -// -// To use Decimal as part of a struct: -// -// type Struct struct { -// Number Decimal -// } -// -// Note: This can "only" represent numbers with a maximum of 2^31 digits after the decimal point. -package decimal - -import ( - "database/sql/driver" - "encoding/binary" - "fmt" - "math" - "math/big" - "regexp" - "strconv" - "strings" -) - -// DivisionPrecision is the number of decimal places in the result when it -// doesn't divide exactly. -// -// Example: -// -// d1 := decimal.NewFromFloat(2).Div(decimal.NewFromFloat(3)) -// d1.String() // output: "0.6666666666666667" -// d2 := decimal.NewFromFloat(2).Div(decimal.NewFromFloat(30000)) -// d2.String() // output: "0.0000666666666667" -// d3 := decimal.NewFromFloat(20000).Div(decimal.NewFromFloat(3)) -// d3.String() // output: "6666.6666666666666667" -// decimal.DivisionPrecision = 3 -// d4 := decimal.NewFromFloat(2).Div(decimal.NewFromFloat(3)) -// d4.String() // output: "0.667" -// -var DivisionPrecision = 16 - -// MarshalJSONWithoutQuotes should be set to true if you want the decimal to -// be JSON marshaled as a number, instead of as a string. -// WARNING: this is dangerous for decimals with many digits, since many JSON -// unmarshallers (ex: Javascript's) will unmarshal JSON numbers to IEEE 754 -// double-precision floating point numbers, which means you can potentially -// silently lose precision. -var MarshalJSONWithoutQuotes = false - -// ExpMaxIterations specifies the maximum number of iterations needed to calculate -// precise natural exponent value using ExpHullAbrham method. -var ExpMaxIterations = 1000 - -// Zero constant, to make computations faster. -// Zero should never be compared with == or != directly, please use decimal.Equal or decimal.Cmp instead. -var Zero = New(0, 1) - -var zeroInt = big.NewInt(0) -var oneInt = big.NewInt(1) -var twoInt = big.NewInt(2) -var fourInt = big.NewInt(4) -var fiveInt = big.NewInt(5) -var tenInt = big.NewInt(10) -var twentyInt = big.NewInt(20) - -var factorials = []Decimal{New(1, 0)} - -// Decimal represents a fixed-point decimal. It is immutable. -// number = value * 10 ^ exp -type Decimal struct { - value *big.Int - - // NOTE(vadim): this must be an int32, because we cast it to float64 during - // calculations. If exp is 64 bit, we might lose precision. - // If we cared about being able to represent every possible decimal, we - // could make exp a *big.Int but it would hurt performance and numbers - // like that are unrealistic. - exp int32 -} - -// New returns a new fixed-point decimal, value * 10 ^ exp. -func New(value int64, exp int32) Decimal { - return Decimal{ - value: big.NewInt(value), - exp: exp, - } -} - -// NewFromInt converts a int64 to Decimal. -// -// Example: -// -// NewFromInt(123).String() // output: "123" -// NewFromInt(-10).String() // output: "-10" -func NewFromInt(value int64) Decimal { - return Decimal{ - value: big.NewInt(value), - exp: 0, - } -} - -// NewFromInt32 converts a int32 to Decimal. -// -// Example: -// -// NewFromInt(123).String() // output: "123" -// NewFromInt(-10).String() // output: "-10" -func NewFromInt32(value int32) Decimal { - return Decimal{ - value: big.NewInt(int64(value)), - exp: 0, - } -} - -// NewFromBigInt returns a new Decimal from a big.Int, value * 10 ^ exp -func NewFromBigInt(value *big.Int, exp int32) Decimal { - return Decimal{ - value: new(big.Int).Set(value), - exp: exp, - } -} - -// NewFromString returns a new Decimal from a string representation. -// Trailing zeroes are not trimmed. -// -// Example: -// -// d, err := NewFromString("-123.45") -// d2, err := NewFromString(".0001") -// d3, err := NewFromString("1.47000") -// -func NewFromString(value string) (Decimal, error) { - originalInput := value - var intString string - var exp int64 - - // Check if number is using scientific notation - eIndex := strings.IndexAny(value, "Ee") - if eIndex != -1 { - expInt, err := strconv.ParseInt(value[eIndex+1:], 10, 32) - if err != nil { - if e, ok := err.(*strconv.NumError); ok && e.Err == strconv.ErrRange { - return Decimal{}, fmt.Errorf("can't convert %s to decimal: fractional part too long", value) - } - return Decimal{}, fmt.Errorf("can't convert %s to decimal: exponent is not numeric", value) - } - value = value[:eIndex] - exp = expInt - } - - pIndex := -1 - vLen := len(value) - for i := 0; i < vLen; i++ { - if value[i] == '.' { - if pIndex > -1 { - return Decimal{}, fmt.Errorf("can't convert %s to decimal: too many .s", value) - } - pIndex = i - } - } - - if pIndex == -1 { - // There is no decimal point, we can just parse the original string as - // an int - intString = value - } else { - if pIndex+1 < vLen { - intString = value[:pIndex] + value[pIndex+1:] - } else { - intString = value[:pIndex] - } - expInt := -len(value[pIndex+1:]) - exp += int64(expInt) - } - - var dValue *big.Int - // strconv.ParseInt is faster than new(big.Int).SetString so this is just a shortcut for strings we know won't overflow - if len(intString) <= 18 { - parsed64, err := strconv.ParseInt(intString, 10, 64) - if err != nil { - return Decimal{}, fmt.Errorf("can't convert %s to decimal", value) - } - dValue = big.NewInt(parsed64) - } else { - dValue = new(big.Int) - _, ok := dValue.SetString(intString, 10) - if !ok { - return Decimal{}, fmt.Errorf("can't convert %s to decimal", value) - } - } - - if exp < math.MinInt32 || exp > math.MaxInt32 { - // NOTE(vadim): I doubt a string could realistically be this long - return Decimal{}, fmt.Errorf("can't convert %s to decimal: fractional part too long", originalInput) - } - - return Decimal{ - value: dValue, - exp: int32(exp), - }, nil -} - -// NewFromFormattedString returns a new Decimal from a formatted string representation. -// The second argument - replRegexp, is a regular expression that is used to find characters that should be -// removed from given decimal string representation. All matched characters will be replaced with an empty string. -// -// Example: -// -// r := regexp.MustCompile("[$,]") -// d1, err := NewFromFormattedString("$5,125.99", r) -// -// r2 := regexp.MustCompile("[_]") -// d2, err := NewFromFormattedString("1_000_000", r2) -// -// r3 := regexp.MustCompile("[USD\\s]") -// d3, err := NewFromFormattedString("5000 USD", r3) -// -func NewFromFormattedString(value string, replRegexp *regexp.Regexp) (Decimal, error) { - parsedValue := replRegexp.ReplaceAllString(value, "") - d, err := NewFromString(parsedValue) - if err != nil { - return Decimal{}, err - } - return d, nil -} - -// RequireFromString returns a new Decimal from a string representation -// or panics if NewFromString would have returned an error. -// -// Example: -// -// d := RequireFromString("-123.45") -// d2 := RequireFromString(".0001") -// -func RequireFromString(value string) Decimal { - dec, err := NewFromString(value) - if err != nil { - panic(err) - } - return dec -} - -// NewFromFloat converts a float64 to Decimal. -// -// The converted number will contain the number of significant digits that can be -// represented in a float with reliable roundtrip. -// This is typically 15 digits, but may be more in some cases. -// See https://www.exploringbinary.com/decimal-precision-of-binary-floating-point-numbers/ for more information. -// -// For slightly faster conversion, use NewFromFloatWithExponent where you can specify the precision in absolute terms. -// -// NOTE: this will panic on NaN, +/-inf -func NewFromFloat(value float64) Decimal { - if value == 0 { - return New(0, 0) - } - return newFromFloat(value, math.Float64bits(value), &float64info) -} - -// NewFromFloat32 converts a float32 to Decimal. -// -// The converted number will contain the number of significant digits that can be -// represented in a float with reliable roundtrip. -// This is typically 6-8 digits depending on the input. -// See https://www.exploringbinary.com/decimal-precision-of-binary-floating-point-numbers/ for more information. -// -// For slightly faster conversion, use NewFromFloatWithExponent where you can specify the precision in absolute terms. -// -// NOTE: this will panic on NaN, +/-inf -func NewFromFloat32(value float32) Decimal { - if value == 0 { - return New(0, 0) - } - // XOR is workaround for https://github.com/golang/go/issues/26285 - a := math.Float32bits(value) ^ 0x80808080 - return newFromFloat(float64(value), uint64(a)^0x80808080, &float32info) -} - -func newFromFloat(val float64, bits uint64, flt *floatInfo) Decimal { - if math.IsNaN(val) || math.IsInf(val, 0) { - panic(fmt.Sprintf("Cannot create a Decimal from %v", val)) - } - exp := int(bits>>flt.mantbits) & (1<>(flt.expbits+flt.mantbits) != 0 - - roundShortest(&d, mant, exp, flt) - // If less than 19 digits, we can do calculation in an int64. - if d.nd < 19 { - tmp := int64(0) - m := int64(1) - for i := d.nd - 1; i >= 0; i-- { - tmp += m * int64(d.d[i]-'0') - m *= 10 - } - if d.neg { - tmp *= -1 - } - return Decimal{value: big.NewInt(tmp), exp: int32(d.dp) - int32(d.nd)} - } - dValue := new(big.Int) - dValue, ok := dValue.SetString(string(d.d[:d.nd]), 10) - if ok { - return Decimal{value: dValue, exp: int32(d.dp) - int32(d.nd)} - } - - return NewFromFloatWithExponent(val, int32(d.dp)-int32(d.nd)) -} - -// NewFromFloatWithExponent converts a float64 to Decimal, with an arbitrary -// number of fractional digits. -// -// Example: -// -// NewFromFloatWithExponent(123.456, -2).String() // output: "123.46" -// -func NewFromFloatWithExponent(value float64, exp int32) Decimal { - if math.IsNaN(value) || math.IsInf(value, 0) { - panic(fmt.Sprintf("Cannot create a Decimal from %v", value)) - } - - bits := math.Float64bits(value) - mant := bits & (1<<52 - 1) - exp2 := int32((bits >> 52) & (1<<11 - 1)) - sign := bits >> 63 - - if exp2 == 0 { - // specials - if mant == 0 { - return Decimal{} - } - // subnormal - exp2++ - } else { - // normal - mant |= 1 << 52 - } - - exp2 -= 1023 + 52 - - // normalizing base-2 values - for mant&1 == 0 { - mant = mant >> 1 - exp2++ - } - - // maximum number of fractional base-10 digits to represent 2^N exactly cannot be more than -N if N<0 - if exp < 0 && exp < exp2 { - if exp2 < 0 { - exp = exp2 - } else { - exp = 0 - } - } - - // representing 10^M * 2^N as 5^M * 2^(M+N) - exp2 -= exp - - temp := big.NewInt(1) - dMant := big.NewInt(int64(mant)) - - // applying 5^M - if exp > 0 { - temp = temp.SetInt64(int64(exp)) - temp = temp.Exp(fiveInt, temp, nil) - } else if exp < 0 { - temp = temp.SetInt64(-int64(exp)) - temp = temp.Exp(fiveInt, temp, nil) - dMant = dMant.Mul(dMant, temp) - temp = temp.SetUint64(1) - } - - // applying 2^(M+N) - if exp2 > 0 { - dMant = dMant.Lsh(dMant, uint(exp2)) - } else if exp2 < 0 { - temp = temp.Lsh(temp, uint(-exp2)) - } - - // rounding and downscaling - if exp > 0 || exp2 < 0 { - halfDown := new(big.Int).Rsh(temp, 1) - dMant = dMant.Add(dMant, halfDown) - dMant = dMant.Quo(dMant, temp) - } - - if sign == 1 { - dMant = dMant.Neg(dMant) - } - - return Decimal{ - value: dMant, - exp: exp, - } -} - -// Copy returns a copy of decimal with the same value and exponent, but a different pointer to value. -func (d Decimal) Copy() Decimal { - d.ensureInitialized() - return Decimal{ - value: &(*d.value), - exp: d.exp, - } -} - -// rescale returns a rescaled version of the decimal. Returned -// decimal may be less precise if the given exponent is bigger -// than the initial exponent of the Decimal. -// NOTE: this will truncate, NOT round -// -// Example: -// -// d := New(12345, -4) -// d2 := d.rescale(-1) -// d3 := d2.rescale(-4) -// println(d1) -// println(d2) -// println(d3) -// -// Output: -// -// 1.2345 -// 1.2 -// 1.2000 -// -func (d Decimal) rescale(exp int32) Decimal { - d.ensureInitialized() - - if d.exp == exp { - return Decimal{ - new(big.Int).Set(d.value), - d.exp, - } - } - - // NOTE(vadim): must convert exps to float64 before - to prevent overflow - diff := math.Abs(float64(exp) - float64(d.exp)) - value := new(big.Int).Set(d.value) - - expScale := new(big.Int).Exp(tenInt, big.NewInt(int64(diff)), nil) - if exp > d.exp { - value = value.Quo(value, expScale) - } else if exp < d.exp { - value = value.Mul(value, expScale) - } - - return Decimal{ - value: value, - exp: exp, - } -} - -// Abs returns the absolute value of the decimal. -func (d Decimal) Abs() Decimal { - if !d.IsNegative() { - return d - } - d.ensureInitialized() - d2Value := new(big.Int).Abs(d.value) - return Decimal{ - value: d2Value, - exp: d.exp, - } -} - -// Add returns d + d2. -func (d Decimal) Add(d2 Decimal) Decimal { - rd, rd2 := RescalePair(d, d2) - - d3Value := new(big.Int).Add(rd.value, rd2.value) - return Decimal{ - value: d3Value, - exp: rd.exp, - } -} - -// Sub returns d - d2. -func (d Decimal) Sub(d2 Decimal) Decimal { - rd, rd2 := RescalePair(d, d2) - - d3Value := new(big.Int).Sub(rd.value, rd2.value) - return Decimal{ - value: d3Value, - exp: rd.exp, - } -} - -// Neg returns -d. -func (d Decimal) Neg() Decimal { - d.ensureInitialized() - val := new(big.Int).Neg(d.value) - return Decimal{ - value: val, - exp: d.exp, - } -} - -// Mul returns d * d2. -func (d Decimal) Mul(d2 Decimal) Decimal { - d.ensureInitialized() - d2.ensureInitialized() - - expInt64 := int64(d.exp) + int64(d2.exp) - if expInt64 > math.MaxInt32 || expInt64 < math.MinInt32 { - // NOTE(vadim): better to panic than give incorrect results, as - // Decimals are usually used for money - panic(fmt.Sprintf("exponent %v overflows an int32!", expInt64)) - } - - d3Value := new(big.Int).Mul(d.value, d2.value) - return Decimal{ - value: d3Value, - exp: int32(expInt64), - } -} - -// Shift shifts the decimal in base 10. -// It shifts left when shift is positive and right if shift is negative. -// In simpler terms, the given value for shift is added to the exponent -// of the decimal. -func (d Decimal) Shift(shift int32) Decimal { - d.ensureInitialized() - return Decimal{ - value: new(big.Int).Set(d.value), - exp: d.exp + shift, - } -} - -// Div returns d / d2. If it doesn't divide exactly, the result will have -// DivisionPrecision digits after the decimal point. -func (d Decimal) Div(d2 Decimal) Decimal { - return d.DivRound(d2, int32(DivisionPrecision)) -} - -// QuoRem does divsion with remainder -// d.QuoRem(d2,precision) returns quotient q and remainder r such that -// d = d2 * q + r, q an integer multiple of 10^(-precision) -// 0 <= r < abs(d2) * 10 ^(-precision) if d>=0 -// 0 >= r > -abs(d2) * 10 ^(-precision) if d<0 -// Note that precision<0 is allowed as input. -func (d Decimal) QuoRem(d2 Decimal, precision int32) (Decimal, Decimal) { - d.ensureInitialized() - d2.ensureInitialized() - if d2.value.Sign() == 0 { - panic("decimal division by 0") - } - scale := -precision - e := int64(d.exp - d2.exp - scale) - if e > math.MaxInt32 || e < math.MinInt32 { - panic("overflow in decimal QuoRem") - } - var aa, bb, expo big.Int - var scalerest int32 - // d = a 10^ea - // d2 = b 10^eb - if e < 0 { - aa = *d.value - expo.SetInt64(-e) - bb.Exp(tenInt, &expo, nil) - bb.Mul(d2.value, &bb) - scalerest = d.exp - // now aa = a - // bb = b 10^(scale + eb - ea) - } else { - expo.SetInt64(e) - aa.Exp(tenInt, &expo, nil) - aa.Mul(d.value, &aa) - bb = *d2.value - scalerest = scale + d2.exp - // now aa = a ^ (ea - eb - scale) - // bb = b - } - var q, r big.Int - q.QuoRem(&aa, &bb, &r) - dq := Decimal{value: &q, exp: scale} - dr := Decimal{value: &r, exp: scalerest} - return dq, dr -} - -// DivRound divides and rounds to a given precision -// i.e. to an integer multiple of 10^(-precision) -// for a positive quotient digit 5 is rounded up, away from 0 -// if the quotient is negative then digit 5 is rounded down, away from 0 -// Note that precision<0 is allowed as input. -func (d Decimal) DivRound(d2 Decimal, precision int32) Decimal { - // QuoRem already checks initialization - q, r := d.QuoRem(d2, precision) - // the actual rounding decision is based on comparing r*10^precision and d2/2 - // instead compare 2 r 10 ^precision and d2 - var rv2 big.Int - rv2.Abs(r.value) - rv2.Lsh(&rv2, 1) - // now rv2 = abs(r.value) * 2 - r2 := Decimal{value: &rv2, exp: r.exp + precision} - // r2 is now 2 * r * 10 ^ precision - var c = r2.Cmp(d2.Abs()) - - if c < 0 { - return q - } - - if d.value.Sign()*d2.value.Sign() < 0 { - return q.Sub(New(1, -precision)) - } - - return q.Add(New(1, -precision)) -} - -// Mod returns d % d2. -func (d Decimal) Mod(d2 Decimal) Decimal { - quo := d.Div(d2).Truncate(0) - return d.Sub(d2.Mul(quo)) -} - -// Pow returns d to the power d2 -func (d Decimal) Pow(d2 Decimal) Decimal { - var temp Decimal - if d2.IntPart() == 0 { - return NewFromFloat(1) - } - temp = d.Pow(d2.Div(NewFromFloat(2))) - if d2.IntPart()%2 == 0 { - return temp.Mul(temp) - } - if d2.IntPart() > 0 { - return temp.Mul(temp).Mul(d) - } - return temp.Mul(temp).Div(d) -} - -// ExpHullAbrham calculates the natural exponent of decimal (e to the power of d) using Hull-Abraham algorithm. -// OverallPrecision argument specifies the overall precision of the result (integer part + decimal part). -// -// ExpHullAbrham is faster than ExpTaylor for small precision values, but it is much slower for large precision values. -// -// Example: -// -// NewFromFloat(26.1).ExpHullAbrham(2).String() // output: "220000000000" -// NewFromFloat(26.1).ExpHullAbrham(20).String() // output: "216314672147.05767284" -// -func (d Decimal) ExpHullAbrham(overallPrecision uint32) (Decimal, error) { - // Algorithm based on Variable precision exponential function. - // ACM Transactions on Mathematical Software by T. E. Hull & A. Abrham. - if d.IsZero() { - return Decimal{oneInt, 0}, nil - } - - currentPrecision := overallPrecision - - // Algorithm does not work if currentPrecision * 23 < |x|. - // Precision is automatically increased in such cases, so the value can be calculated precisely. - // If newly calculated precision is higher than ExpMaxIterations the currentPrecision will not be changed. - f := d.Abs().InexactFloat64() - if ncp := f / 23; ncp > float64(currentPrecision) && ncp < float64(ExpMaxIterations) { - currentPrecision = uint32(math.Ceil(ncp)) - } - - // fail if abs(d) beyond an over/underflow threshold - overflowThreshold := New(23*int64(currentPrecision), 0) - if d.Abs().Cmp(overflowThreshold) > 0 { - return Decimal{}, fmt.Errorf("over/underflow threshold, exp(x) cannot be calculated precisely") - } - - // Return 1 if abs(d) small enough; this also avoids later over/underflow - overflowThreshold2 := New(9, -int32(currentPrecision)-1) - if d.Abs().Cmp(overflowThreshold2) <= 0 { - return Decimal{oneInt, d.exp}, nil - } - - // t is the smallest integer >= 0 such that the corresponding abs(d/k) < 1 - t := d.exp + int32(d.NumDigits()) // Add d.NumDigits because the paper assumes that d.value [0.1, 1) - - if t < 0 { - t = 0 - } - - k := New(1, t) // reduction factor - r := Decimal{new(big.Int).Set(d.value), d.exp - t} // reduced argument - p := int32(currentPrecision) + t + 2 // precision for calculating the sum - - // Determine n, the number of therms for calculating sum - // use first Newton step (1.435p - 1.182) / log10(p/abs(r)) - // for solving appropriate equation, along with directed - // roundings and simple rational bound for log10(p/abs(r)) - rf := r.Abs().InexactFloat64() - pf := float64(p) - nf := math.Ceil((1.453*pf - 1.182) / math.Log10(pf/rf)) - if nf > float64(ExpMaxIterations) || math.IsNaN(nf) { - return Decimal{}, fmt.Errorf("exact value cannot be calculated in <=ExpMaxIterations iterations") - } - n := int64(nf) - - tmp := New(0, 0) - sum := New(1, 0) - one := New(1, 0) - for i := n - 1; i > 0; i-- { - tmp.value.SetInt64(i) - sum = sum.Mul(r.DivRound(tmp, p)) - sum = sum.Add(one) - } - - ki := k.IntPart() - res := New(1, 0) - for i := ki; i > 0; i-- { - res = res.Mul(sum) - } - - resNumDigits := int32(res.NumDigits()) - - var roundDigits int32 - if resNumDigits > abs(res.exp) { - roundDigits = int32(currentPrecision) - resNumDigits - res.exp - } else { - roundDigits = int32(currentPrecision) - } - - res = res.Round(roundDigits) - - return res, nil -} - -// ExpTaylor calculates the natural exponent of decimal (e to the power of d) using Taylor series expansion. -// Precision argument specifies how precise the result must be (number of digits after decimal point). -// Negative precision is allowed. -// -// ExpTaylor is much faster for large precision values than ExpHullAbrham. -// -// Example: -// -// d, err := NewFromFloat(26.1).ExpTaylor(2).String() -// d.String() // output: "216314672147.06" -// -// NewFromFloat(26.1).ExpTaylor(20).String() -// d.String() // output: "216314672147.05767284062928674083" -// -// NewFromFloat(26.1).ExpTaylor(-10).String() -// d.String() // output: "220000000000" -// -func (d Decimal) ExpTaylor(precision int32) (Decimal, error) { - // Note(mwoss): Implementation can be optimized by exclusively using big.Int API only - if d.IsZero() { - return Decimal{oneInt, 0}.Round(precision), nil - } - - var epsilon Decimal - var divPrecision int32 - if precision < 0 { - epsilon = New(1, -1) - divPrecision = 8 - } else { - epsilon = New(1, -precision-1) - divPrecision = precision + 1 - } - - decAbs := d.Abs() - pow := d.Abs() - factorial := New(1, 0) - - result := New(1, 0) - - for i := int64(1); ; { - step := pow.DivRound(factorial, divPrecision) - result = result.Add(step) - - // Stop Taylor series when current step is smaller than epsilon - if step.Cmp(epsilon) < 0 { - break - } - - pow = pow.Mul(decAbs) - - i++ - - // Calculate next factorial number or retrieve cached value - if len(factorials) >= int(i) && !factorials[i-1].IsZero() { - factorial = factorials[i-1] - } else { - // To avoid any race conditions, firstly the zero value is appended to a slice to create - // a spot for newly calculated factorial. After that, the zero value is replaced by calculated - // factorial using the index notation. - factorial = factorials[i-2].Mul(New(i, 0)) - factorials = append(factorials, Zero) - factorials[i-1] = factorial - } - } - - if d.Sign() < 0 { - result = New(1, 0).DivRound(result, precision+1) - } - - result = result.Round(precision) - return result, nil -} - -// NumDigits returns the number of digits of the decimal coefficient (d.Value) -// Note: Current implementation is extremely slow for large decimals and/or decimals with large fractional part -func (d Decimal) NumDigits() int { - // Note(mwoss): It can be optimized, unnecessary cast of big.Int to string - if d.IsNegative() { - return len(d.value.String()) - 1 - } - return len(d.value.String()) -} - -// IsInteger returns true when decimal can be represented as an integer value, otherwise, it returns false. -func (d Decimal) IsInteger() bool { - // The most typical case, all decimal with exponent higher or equal 0 can be represented as integer - if d.exp >= 0 { - return true - } - // When the exponent is negative we have to check every number after the decimal place - // If all of them are zeroes, we are sure that given decimal can be represented as an integer - var r big.Int - q := new(big.Int).Set(d.value) - for z := abs(d.exp); z > 0; z-- { - q.QuoRem(q, tenInt, &r) - if r.Cmp(zeroInt) != 0 { - return false - } - } - return true -} - -// Abs calculates absolute value of any int32. Used for calculating absolute value of decimal's exponent. -func abs(n int32) int32 { - if n < 0 { - return -n - } - return n -} - -// Cmp compares the numbers represented by d and d2 and returns: -// -// -1 if d < d2 -// 0 if d == d2 -// +1 if d > d2 -// -func (d Decimal) Cmp(d2 Decimal) int { - d.ensureInitialized() - d2.ensureInitialized() - - if d.exp == d2.exp { - return d.value.Cmp(d2.value) - } - - rd, rd2 := RescalePair(d, d2) - - return rd.value.Cmp(rd2.value) -} - -// Equal returns whether the numbers represented by d and d2 are equal. -func (d Decimal) Equal(d2 Decimal) bool { - return d.Cmp(d2) == 0 -} - -// Equals is deprecated, please use Equal method instead -func (d Decimal) Equals(d2 Decimal) bool { - return d.Equal(d2) -} - -// GreaterThan (GT) returns true when d is greater than d2. -func (d Decimal) GreaterThan(d2 Decimal) bool { - return d.Cmp(d2) == 1 -} - -// GreaterThanOrEqual (GTE) returns true when d is greater than or equal to d2. -func (d Decimal) GreaterThanOrEqual(d2 Decimal) bool { - cmp := d.Cmp(d2) - return cmp == 1 || cmp == 0 -} - -// LessThan (LT) returns true when d is less than d2. -func (d Decimal) LessThan(d2 Decimal) bool { - return d.Cmp(d2) == -1 -} - -// LessThanOrEqual (LTE) returns true when d is less than or equal to d2. -func (d Decimal) LessThanOrEqual(d2 Decimal) bool { - cmp := d.Cmp(d2) - return cmp == -1 || cmp == 0 -} - -// Sign returns: -// -// -1 if d < 0 -// 0 if d == 0 -// +1 if d > 0 -// -func (d Decimal) Sign() int { - if d.value == nil { - return 0 - } - return d.value.Sign() -} - -// IsPositive return -// -// true if d > 0 -// false if d == 0 -// false if d < 0 -func (d Decimal) IsPositive() bool { - return d.Sign() == 1 -} - -// IsNegative return -// -// true if d < 0 -// false if d == 0 -// false if d > 0 -func (d Decimal) IsNegative() bool { - return d.Sign() == -1 -} - -// IsZero return -// -// true if d == 0 -// false if d > 0 -// false if d < 0 -func (d Decimal) IsZero() bool { - return d.Sign() == 0 -} - -// Exponent returns the exponent, or scale component of the decimal. -func (d Decimal) Exponent() int32 { - return d.exp -} - -// Coefficient returns the coefficient of the decimal. It is scaled by 10^Exponent() -func (d Decimal) Coefficient() *big.Int { - d.ensureInitialized() - // we copy the coefficient so that mutating the result does not mutate the Decimal. - return new(big.Int).Set(d.value) -} - -// CoefficientInt64 returns the coefficient of the decimal as int64. It is scaled by 10^Exponent() -// If coefficient cannot be represented in an int64, the result will be undefined. -func (d Decimal) CoefficientInt64() int64 { - d.ensureInitialized() - return d.value.Int64() -} - -// IntPart returns the integer component of the decimal. -func (d Decimal) IntPart() int64 { - scaledD := d.rescale(0) - return scaledD.value.Int64() -} - -// BigInt returns integer component of the decimal as a BigInt. -func (d Decimal) BigInt() *big.Int { - scaledD := d.rescale(0) - i := &big.Int{} - i.SetString(scaledD.String(), 10) - return i -} - -// BigFloat returns decimal as BigFloat. -// Be aware that casting decimal to BigFloat might cause a loss of precision. -func (d Decimal) BigFloat() *big.Float { - f := &big.Float{} - f.SetString(d.String()) - return f -} - -// Rat returns a rational number representation of the decimal. -func (d Decimal) Rat() *big.Rat { - d.ensureInitialized() - if d.exp <= 0 { - // NOTE(vadim): must negate after casting to prevent int32 overflow - denom := new(big.Int).Exp(tenInt, big.NewInt(-int64(d.exp)), nil) - return new(big.Rat).SetFrac(d.value, denom) - } - - mul := new(big.Int).Exp(tenInt, big.NewInt(int64(d.exp)), nil) - num := new(big.Int).Mul(d.value, mul) - return new(big.Rat).SetFrac(num, oneInt) -} - -// Float64 returns the nearest float64 value for d and a bool indicating -// whether f represents d exactly. -// For more details, see the documentation for big.Rat.Float64 -func (d Decimal) Float64() (f float64, exact bool) { - return d.Rat().Float64() -} - -// InexactFloat64 returns the nearest float64 value for d. -// It doesn't indicate if the returned value represents d exactly. -func (d Decimal) InexactFloat64() float64 { - f, _ := d.Float64() - return f -} - -// String returns the string representation of the decimal -// with the fixed point. -// -// Example: -// -// d := New(-12345, -3) -// println(d.String()) -// -// Output: -// -// -12.345 -// -func (d Decimal) String() string { - return d.string(true) -} - -// StringFixed returns a rounded fixed-point string with places digits after -// the decimal point. -// -// Example: -// -// NewFromFloat(0).StringFixed(2) // output: "0.00" -// NewFromFloat(0).StringFixed(0) // output: "0" -// NewFromFloat(5.45).StringFixed(0) // output: "5" -// NewFromFloat(5.45).StringFixed(1) // output: "5.5" -// NewFromFloat(5.45).StringFixed(2) // output: "5.45" -// NewFromFloat(5.45).StringFixed(3) // output: "5.450" -// NewFromFloat(545).StringFixed(-1) // output: "550" -// -func (d Decimal) StringFixed(places int32) string { - rounded := d.Round(places) - return rounded.string(false) -} - -// StringFixedBank returns a banker rounded fixed-point string with places digits -// after the decimal point. -// -// Example: -// -// NewFromFloat(0).StringFixedBank(2) // output: "0.00" -// NewFromFloat(0).StringFixedBank(0) // output: "0" -// NewFromFloat(5.45).StringFixedBank(0) // output: "5" -// NewFromFloat(5.45).StringFixedBank(1) // output: "5.4" -// NewFromFloat(5.45).StringFixedBank(2) // output: "5.45" -// NewFromFloat(5.45).StringFixedBank(3) // output: "5.450" -// NewFromFloat(545).StringFixedBank(-1) // output: "540" -// -func (d Decimal) StringFixedBank(places int32) string { - rounded := d.RoundBank(places) - return rounded.string(false) -} - -// StringFixedCash returns a Swedish/Cash rounded fixed-point string. For -// more details see the documentation at function RoundCash. -func (d Decimal) StringFixedCash(interval uint8) string { - rounded := d.RoundCash(interval) - return rounded.string(false) -} - -// Round rounds the decimal to places decimal places. -// If places < 0, it will round the integer part to the nearest 10^(-places). -// -// Example: -// -// NewFromFloat(5.45).Round(1).String() // output: "5.5" -// NewFromFloat(545).Round(-1).String() // output: "550" -// -func (d Decimal) Round(places int32) Decimal { - if d.exp == -places { - return d - } - // truncate to places + 1 - ret := d.rescale(-places - 1) - - // add sign(d) * 0.5 - if ret.value.Sign() < 0 { - ret.value.Sub(ret.value, fiveInt) - } else { - ret.value.Add(ret.value, fiveInt) - } - - // floor for positive numbers, ceil for negative numbers - _, m := ret.value.DivMod(ret.value, tenInt, new(big.Int)) - ret.exp++ - if ret.value.Sign() < 0 && m.Cmp(zeroInt) != 0 { - ret.value.Add(ret.value, oneInt) - } - - return ret -} - -// RoundCeil rounds the decimal towards +infinity. -// -// Example: -// -// NewFromFloat(545).RoundCeil(-2).String() // output: "600" -// NewFromFloat(500).RoundCeil(-2).String() // output: "500" -// NewFromFloat(1.1001).RoundCeil(2).String() // output: "1.11" -// NewFromFloat(-1.454).RoundCeil(1).String() // output: "-1.5" -// -func (d Decimal) RoundCeil(places int32) Decimal { - if d.exp >= -places { - return d - } - - rescaled := d.rescale(-places) - if d.Equal(rescaled) { - return d - } - - if d.value.Sign() > 0 { - rescaled.value.Add(rescaled.value, oneInt) - } - - return rescaled -} - -// RoundFloor rounds the decimal towards -infinity. -// -// Example: -// -// NewFromFloat(545).RoundFloor(-2).String() // output: "500" -// NewFromFloat(-500).RoundFloor(-2).String() // output: "-500" -// NewFromFloat(1.1001).RoundFloor(2).String() // output: "1.1" -// NewFromFloat(-1.454).RoundFloor(1).String() // output: "-1.4" -// -func (d Decimal) RoundFloor(places int32) Decimal { - if d.exp >= -places { - return d - } - - rescaled := d.rescale(-places) - if d.Equal(rescaled) { - return d - } - - if d.value.Sign() < 0 { - rescaled.value.Sub(rescaled.value, oneInt) - } - - return rescaled -} - -// RoundUp rounds the decimal away from zero. -// -// Example: -// -// NewFromFloat(545).RoundUp(-2).String() // output: "600" -// NewFromFloat(500).RoundUp(-2).String() // output: "500" -// NewFromFloat(1.1001).RoundUp(2).String() // output: "1.11" -// NewFromFloat(-1.454).RoundUp(1).String() // output: "-1.4" -// -func (d Decimal) RoundUp(places int32) Decimal { - if d.exp >= -places { - return d - } - - rescaled := d.rescale(-places) - if d.Equal(rescaled) { - return d - } - - if d.value.Sign() > 0 { - rescaled.value.Add(rescaled.value, oneInt) - } else if d.value.Sign() < 0 { - rescaled.value.Sub(rescaled.value, oneInt) - } - - return rescaled -} - -// RoundDown rounds the decimal towards zero. -// -// Example: -// -// NewFromFloat(545).RoundDown(-2).String() // output: "500" -// NewFromFloat(-500).RoundDown(-2).String() // output: "-500" -// NewFromFloat(1.1001).RoundDown(2).String() // output: "1.1" -// NewFromFloat(-1.454).RoundDown(1).String() // output: "-1.5" -// -func (d Decimal) RoundDown(places int32) Decimal { - if d.exp >= -places { - return d - } - - rescaled := d.rescale(-places) - if d.Equal(rescaled) { - return d - } - return rescaled -} - -// RoundBank rounds the decimal to places decimal places. -// If the final digit to round is equidistant from the nearest two integers the -// rounded value is taken as the even number -// -// If places < 0, it will round the integer part to the nearest 10^(-places). -// -// Examples: -// -// NewFromFloat(5.45).RoundBank(1).String() // output: "5.4" -// NewFromFloat(545).RoundBank(-1).String() // output: "540" -// NewFromFloat(5.46).RoundBank(1).String() // output: "5.5" -// NewFromFloat(546).RoundBank(-1).String() // output: "550" -// NewFromFloat(5.55).RoundBank(1).String() // output: "5.6" -// NewFromFloat(555).RoundBank(-1).String() // output: "560" -// -func (d Decimal) RoundBank(places int32) Decimal { - - round := d.Round(places) - remainder := d.Sub(round).Abs() - - half := New(5, -places-1) - if remainder.Cmp(half) == 0 && round.value.Bit(0) != 0 { - if round.value.Sign() < 0 { - round.value.Add(round.value, oneInt) - } else { - round.value.Sub(round.value, oneInt) - } - } - - return round -} - -// RoundCash aka Cash/Penny/öre rounding rounds decimal to a specific -// interval. The amount payable for a cash transaction is rounded to the nearest -// multiple of the minimum currency unit available. The following intervals are -// available: 5, 10, 25, 50 and 100; any other number throws a panic. -// 5: 5 cent rounding 3.43 => 3.45 -// 10: 10 cent rounding 3.45 => 3.50 (5 gets rounded up) -// 25: 25 cent rounding 3.41 => 3.50 -// 50: 50 cent rounding 3.75 => 4.00 -// 100: 100 cent rounding 3.50 => 4.00 -// For more details: https://en.wikipedia.org/wiki/Cash_rounding -func (d Decimal) RoundCash(interval uint8) Decimal { - var iVal *big.Int - switch interval { - case 5: - iVal = twentyInt - case 10: - iVal = tenInt - case 25: - iVal = fourInt - case 50: - iVal = twoInt - case 100: - iVal = oneInt - default: - panic(fmt.Sprintf("Decimal does not support this Cash rounding interval `%d`. Supported: 5, 10, 25, 50, 100", interval)) - } - dVal := Decimal{ - value: iVal, - } - - // TODO: optimize those calculations to reduce the high allocations (~29 allocs). - return d.Mul(dVal).Round(0).Div(dVal).Truncate(2) -} - -// Floor returns the nearest integer value less than or equal to d. -func (d Decimal) Floor() Decimal { - d.ensureInitialized() - - if d.exp >= 0 { - return d - } - - exp := big.NewInt(10) - - // NOTE(vadim): must negate after casting to prevent int32 overflow - exp.Exp(exp, big.NewInt(-int64(d.exp)), nil) - - z := new(big.Int).Div(d.value, exp) - return Decimal{value: z, exp: 0} -} - -// Ceil returns the nearest integer value greater than or equal to d. -func (d Decimal) Ceil() Decimal { - d.ensureInitialized() - - if d.exp >= 0 { - return d - } - - exp := big.NewInt(10) - - // NOTE(vadim): must negate after casting to prevent int32 overflow - exp.Exp(exp, big.NewInt(-int64(d.exp)), nil) - - z, m := new(big.Int).DivMod(d.value, exp, new(big.Int)) - if m.Cmp(zeroInt) != 0 { - z.Add(z, oneInt) - } - return Decimal{value: z, exp: 0} -} - -// Truncate truncates off digits from the number, without rounding. -// -// NOTE: precision is the last digit that will not be truncated (must be >= 0). -// -// Example: -// -// decimal.NewFromString("123.456").Truncate(2).String() // "123.45" -// -func (d Decimal) Truncate(precision int32) Decimal { - d.ensureInitialized() - if precision >= 0 && -precision > d.exp { - return d.rescale(-precision) - } - return d -} - -// UnmarshalJSON implements the json.Unmarshaler interface. -func (d *Decimal) UnmarshalJSON(decimalBytes []byte) error { - if string(decimalBytes) == "null" { - return nil - } - - str, err := unquoteIfQuoted(decimalBytes) - if err != nil { - return fmt.Errorf("error decoding string '%s': %s", decimalBytes, err) - } - - decimal, err := NewFromString(str) - *d = decimal - if err != nil { - return fmt.Errorf("error decoding string '%s': %s", str, err) - } - return nil -} - -// MarshalJSON implements the json.Marshaler interface. -func (d Decimal) MarshalJSON() ([]byte, error) { - var str string - if MarshalJSONWithoutQuotes { - str = d.String() - } else { - str = "\"" + d.String() + "\"" - } - return []byte(str), nil -} - -// UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. As a string representation -// is already used when encoding to text, this method stores that string as []byte -func (d *Decimal) UnmarshalBinary(data []byte) error { - // Verify we have at least 4 bytes for the exponent. The GOB encoded value - // may be empty. - if len(data) < 4 { - return fmt.Errorf("error decoding binary %v: expected at least 4 bytes, got %d", data, len(data)) - } - - // Extract the exponent - d.exp = int32(binary.BigEndian.Uint32(data[:4])) - - // Extract the value - d.value = new(big.Int) - if err := d.value.GobDecode(data[4:]); err != nil { - return fmt.Errorf("error decoding binary %v: %s", data, err) - } - - return nil -} - -// MarshalBinary implements the encoding.BinaryMarshaler interface. -func (d Decimal) MarshalBinary() (data []byte, err error) { - // Write the exponent first since it's a fixed size - v1 := make([]byte, 4) - binary.BigEndian.PutUint32(v1, uint32(d.exp)) - - // Add the value - var v2 []byte - if v2, err = d.value.GobEncode(); err != nil { - return - } - - // Return the byte array - data = append(v1, v2...) - return -} - -// Scan implements the sql.Scanner interface for database deserialization. -func (d *Decimal) Scan(value interface{}) error { - // first try to see if the data is stored in database as a Numeric datatype - switch v := value.(type) { - - case float32: - *d = NewFromFloat(float64(v)) - return nil - - case float64: - // numeric in sqlite3 sends us float64 - *d = NewFromFloat(v) - return nil - - case int64: - // at least in sqlite3 when the value is 0 in db, the data is sent - // to us as an int64 instead of a float64 ... - *d = New(v, 0) - return nil - - default: - // default is trying to interpret value stored as string - str, err := unquoteIfQuoted(v) - if err != nil { - return err - } - *d, err = NewFromString(str) - return err - } -} - -// Value implements the driver.Valuer interface for database serialization. -func (d Decimal) Value() (driver.Value, error) { - return d.String(), nil -} - -// UnmarshalText implements the encoding.TextUnmarshaler interface for XML -// deserialization. -func (d *Decimal) UnmarshalText(text []byte) error { - str := string(text) - - dec, err := NewFromString(str) - *d = dec - if err != nil { - return fmt.Errorf("error decoding string '%s': %s", str, err) - } - - return nil -} - -// MarshalText implements the encoding.TextMarshaler interface for XML -// serialization. -func (d Decimal) MarshalText() (text []byte, err error) { - return []byte(d.String()), nil -} - -// GobEncode implements the gob.GobEncoder interface for gob serialization. -func (d Decimal) GobEncode() ([]byte, error) { - return d.MarshalBinary() -} - -// GobDecode implements the gob.GobDecoder interface for gob serialization. -func (d *Decimal) GobDecode(data []byte) error { - return d.UnmarshalBinary(data) -} - -// StringScaled first scales the decimal then calls .String() on it. -// NOTE: buggy, unintuitive, and DEPRECATED! Use StringFixed instead. -func (d Decimal) StringScaled(exp int32) string { - return d.rescale(exp).String() -} - -func (d Decimal) string(trimTrailingZeros bool) string { - if d.exp >= 0 { - return d.rescale(0).value.String() - } - - abs := new(big.Int).Abs(d.value) - str := abs.String() - - var intPart, fractionalPart string - - // NOTE(vadim): this cast to int will cause bugs if d.exp == INT_MIN - // and you are on a 32-bit machine. Won't fix this super-edge case. - dExpInt := int(d.exp) - if len(str) > -dExpInt { - intPart = str[:len(str)+dExpInt] - fractionalPart = str[len(str)+dExpInt:] - } else { - intPart = "0" - - num0s := -dExpInt - len(str) - fractionalPart = strings.Repeat("0", num0s) + str - } - - if trimTrailingZeros { - i := len(fractionalPart) - 1 - for ; i >= 0; i-- { - if fractionalPart[i] != '0' { - break - } - } - fractionalPart = fractionalPart[:i+1] - } - - number := intPart - if len(fractionalPart) > 0 { - number += "." + fractionalPart - } - - if d.value.Sign() < 0 { - return "-" + number - } - - return number -} - -func (d *Decimal) ensureInitialized() { - if d.value == nil { - d.value = new(big.Int) - } -} - -// Min returns the smallest Decimal that was passed in the arguments. -// -// To call this function with an array, you must do: -// -// Min(arr[0], arr[1:]...) -// -// This makes it harder to accidentally call Min with 0 arguments. -func Min(first Decimal, rest ...Decimal) Decimal { - ans := first - for _, item := range rest { - if item.Cmp(ans) < 0 { - ans = item - } - } - return ans -} - -// Max returns the largest Decimal that was passed in the arguments. -// -// To call this function with an array, you must do: -// -// Max(arr[0], arr[1:]...) -// -// This makes it harder to accidentally call Max with 0 arguments. -func Max(first Decimal, rest ...Decimal) Decimal { - ans := first - for _, item := range rest { - if item.Cmp(ans) > 0 { - ans = item - } - } - return ans -} - -// Sum returns the combined total of the provided first and rest Decimals -func Sum(first Decimal, rest ...Decimal) Decimal { - total := first - for _, item := range rest { - total = total.Add(item) - } - - return total -} - -// Avg returns the average value of the provided first and rest Decimals -func Avg(first Decimal, rest ...Decimal) Decimal { - count := New(int64(len(rest)+1), 0) - sum := Sum(first, rest...) - return sum.Div(count) -} - -// RescalePair rescales two decimals to common exponential value (minimal exp of both decimals) -func RescalePair(d1 Decimal, d2 Decimal) (Decimal, Decimal) { - d1.ensureInitialized() - d2.ensureInitialized() - - if d1.exp == d2.exp { - return d1, d2 - } - - baseScale := min(d1.exp, d2.exp) - if baseScale != d1.exp { - return d1.rescale(baseScale), d2 - } - return d1, d2.rescale(baseScale) -} - -func min(x, y int32) int32 { - if x >= y { - return y - } - return x -} - -func unquoteIfQuoted(value interface{}) (string, error) { - var bytes []byte - - switch v := value.(type) { - case string: - bytes = []byte(v) - case []byte: - bytes = v - default: - return "", fmt.Errorf("could not convert value '%+v' to byte array of type '%T'", - value, value) - } - - // If the amount is quoted, strip the quotes - if len(bytes) > 2 && bytes[0] == '"' && bytes[len(bytes)-1] == '"' { - bytes = bytes[1 : len(bytes)-1] - } - return string(bytes), nil -} - -// NullDecimal represents a nullable decimal with compatibility for -// scanning null values from the database. -type NullDecimal struct { - Decimal Decimal - Valid bool -} - -func NewNullDecimal(d Decimal) NullDecimal { - return NullDecimal{ - Decimal: d, - Valid: true, - } -} - -// Scan implements the sql.Scanner interface for database deserialization. -func (d *NullDecimal) Scan(value interface{}) error { - if value == nil { - d.Valid = false - return nil - } - d.Valid = true - return d.Decimal.Scan(value) -} - -// Value implements the driver.Valuer interface for database serialization. -func (d NullDecimal) Value() (driver.Value, error) { - if !d.Valid { - return nil, nil - } - return d.Decimal.Value() -} - -// UnmarshalJSON implements the json.Unmarshaler interface. -func (d *NullDecimal) UnmarshalJSON(decimalBytes []byte) error { - if string(decimalBytes) == "null" { - d.Valid = false - return nil - } - d.Valid = true - return d.Decimal.UnmarshalJSON(decimalBytes) -} - -// MarshalJSON implements the json.Marshaler interface. -func (d NullDecimal) MarshalJSON() ([]byte, error) { - if !d.Valid { - return []byte("null"), nil - } - return d.Decimal.MarshalJSON() -} - -// UnmarshalText implements the encoding.TextUnmarshaler interface for XML -// deserialization -func (d *NullDecimal) UnmarshalText(text []byte) error { - str := string(text) - - // check for empty XML or XML without body e.g., - if str == "" { - d.Valid = false - return nil - } - if err := d.Decimal.UnmarshalText(text); err != nil { - d.Valid = false - return err - } - d.Valid = true - return nil -} - -// MarshalText implements the encoding.TextMarshaler interface for XML -// serialization. -func (d NullDecimal) MarshalText() (text []byte, err error) { - if !d.Valid { - return []byte{}, nil - } - return d.Decimal.MarshalText() -} - -// Trig functions - -// Atan returns the arctangent, in radians, of x. -func (d Decimal) Atan() Decimal { - if d.Equal(NewFromFloat(0.0)) { - return d - } - if d.GreaterThan(NewFromFloat(0.0)) { - return d.satan() - } - return d.Neg().satan().Neg() -} - -func (d Decimal) xatan() Decimal { - P0 := NewFromFloat(-8.750608600031904122785e-01) - P1 := NewFromFloat(-1.615753718733365076637e+01) - P2 := NewFromFloat(-7.500855792314704667340e+01) - P3 := NewFromFloat(-1.228866684490136173410e+02) - P4 := NewFromFloat(-6.485021904942025371773e+01) - Q0 := NewFromFloat(2.485846490142306297962e+01) - Q1 := NewFromFloat(1.650270098316988542046e+02) - Q2 := NewFromFloat(4.328810604912902668951e+02) - Q3 := NewFromFloat(4.853903996359136964868e+02) - Q4 := NewFromFloat(1.945506571482613964425e+02) - z := d.Mul(d) - b1 := P0.Mul(z).Add(P1).Mul(z).Add(P2).Mul(z).Add(P3).Mul(z).Add(P4).Mul(z) - b2 := z.Add(Q0).Mul(z).Add(Q1).Mul(z).Add(Q2).Mul(z).Add(Q3).Mul(z).Add(Q4) - z = b1.Div(b2) - z = d.Mul(z).Add(d) - return z -} - -// satan reduces its argument (known to be positive) -// to the range [0, 0.66] and calls xatan. -func (d Decimal) satan() Decimal { - Morebits := NewFromFloat(6.123233995736765886130e-17) // pi/2 = PIO2 + Morebits - Tan3pio8 := NewFromFloat(2.41421356237309504880) // tan(3*pi/8) - pi := NewFromFloat(3.14159265358979323846264338327950288419716939937510582097494459) - - if d.LessThanOrEqual(NewFromFloat(0.66)) { - return d.xatan() - } - if d.GreaterThan(Tan3pio8) { - return pi.Div(NewFromFloat(2.0)).Sub(NewFromFloat(1.0).Div(d).xatan()).Add(Morebits) - } - return pi.Div(NewFromFloat(4.0)).Add((d.Sub(NewFromFloat(1.0)).Div(d.Add(NewFromFloat(1.0)))).xatan()).Add(NewFromFloat(0.5).Mul(Morebits)) -} - -// sin coefficients -var _sin = [...]Decimal{ - NewFromFloat(1.58962301576546568060e-10), // 0x3de5d8fd1fd19ccd - NewFromFloat(-2.50507477628578072866e-8), // 0xbe5ae5e5a9291f5d - NewFromFloat(2.75573136213857245213e-6), // 0x3ec71de3567d48a1 - NewFromFloat(-1.98412698295895385996e-4), // 0xbf2a01a019bfdf03 - NewFromFloat(8.33333333332211858878e-3), // 0x3f8111111110f7d0 - NewFromFloat(-1.66666666666666307295e-1), // 0xbfc5555555555548 -} - -// Sin returns the sine of the radian argument x. -func (d Decimal) Sin() Decimal { - PI4A := NewFromFloat(7.85398125648498535156e-1) // 0x3fe921fb40000000, Pi/4 split into three parts - PI4B := NewFromFloat(3.77489470793079817668e-8) // 0x3e64442d00000000, - PI4C := NewFromFloat(2.69515142907905952645e-15) // 0x3ce8469898cc5170, - M4PI := NewFromFloat(1.273239544735162542821171882678754627704620361328125) // 4/pi - - if d.Equal(NewFromFloat(0.0)) { - return d - } - // make argument positive but save the sign - sign := false - if d.LessThan(NewFromFloat(0.0)) { - d = d.Neg() - sign = true - } - - j := d.Mul(M4PI).IntPart() // integer part of x/(Pi/4), as integer for tests on the phase angle - y := NewFromFloat(float64(j)) // integer part of x/(Pi/4), as float - - // map zeros to origin - if j&1 == 1 { - j++ - y = y.Add(NewFromFloat(1.0)) - } - j &= 7 // octant modulo 2Pi radians (360 degrees) - // reflect in x axis - if j > 3 { - sign = !sign - j -= 4 - } - z := d.Sub(y.Mul(PI4A)).Sub(y.Mul(PI4B)).Sub(y.Mul(PI4C)) // Extended precision modular arithmetic - zz := z.Mul(z) - - if j == 1 || j == 2 { - w := zz.Mul(zz).Mul(_cos[0].Mul(zz).Add(_cos[1]).Mul(zz).Add(_cos[2]).Mul(zz).Add(_cos[3]).Mul(zz).Add(_cos[4]).Mul(zz).Add(_cos[5])) - y = NewFromFloat(1.0).Sub(NewFromFloat(0.5).Mul(zz)).Add(w) - } else { - y = z.Add(z.Mul(zz).Mul(_sin[0].Mul(zz).Add(_sin[1]).Mul(zz).Add(_sin[2]).Mul(zz).Add(_sin[3]).Mul(zz).Add(_sin[4]).Mul(zz).Add(_sin[5]))) - } - if sign { - y = y.Neg() - } - return y -} - -// cos coefficients -var _cos = [...]Decimal{ - NewFromFloat(-1.13585365213876817300e-11), // 0xbda8fa49a0861a9b - NewFromFloat(2.08757008419747316778e-9), // 0x3e21ee9d7b4e3f05 - NewFromFloat(-2.75573141792967388112e-7), // 0xbe927e4f7eac4bc6 - NewFromFloat(2.48015872888517045348e-5), // 0x3efa01a019c844f5 - NewFromFloat(-1.38888888888730564116e-3), // 0xbf56c16c16c14f91 - NewFromFloat(4.16666666666665929218e-2), // 0x3fa555555555554b -} - -// Cos returns the cosine of the radian argument x. -func (d Decimal) Cos() Decimal { - - PI4A := NewFromFloat(7.85398125648498535156e-1) // 0x3fe921fb40000000, Pi/4 split into three parts - PI4B := NewFromFloat(3.77489470793079817668e-8) // 0x3e64442d00000000, - PI4C := NewFromFloat(2.69515142907905952645e-15) // 0x3ce8469898cc5170, - M4PI := NewFromFloat(1.273239544735162542821171882678754627704620361328125) // 4/pi - - // make argument positive - sign := false - if d.LessThan(NewFromFloat(0.0)) { - d = d.Neg() - } - - j := d.Mul(M4PI).IntPart() // integer part of x/(Pi/4), as integer for tests on the phase angle - y := NewFromFloat(float64(j)) // integer part of x/(Pi/4), as float - - // map zeros to origin - if j&1 == 1 { - j++ - y = y.Add(NewFromFloat(1.0)) - } - j &= 7 // octant modulo 2Pi radians (360 degrees) - // reflect in x axis - if j > 3 { - sign = !sign - j -= 4 - } - if j > 1 { - sign = !sign - } - - z := d.Sub(y.Mul(PI4A)).Sub(y.Mul(PI4B)).Sub(y.Mul(PI4C)) // Extended precision modular arithmetic - zz := z.Mul(z) - - if j == 1 || j == 2 { - y = z.Add(z.Mul(zz).Mul(_sin[0].Mul(zz).Add(_sin[1]).Mul(zz).Add(_sin[2]).Mul(zz).Add(_sin[3]).Mul(zz).Add(_sin[4]).Mul(zz).Add(_sin[5]))) - } else { - w := zz.Mul(zz).Mul(_cos[0].Mul(zz).Add(_cos[1]).Mul(zz).Add(_cos[2]).Mul(zz).Add(_cos[3]).Mul(zz).Add(_cos[4]).Mul(zz).Add(_cos[5])) - y = NewFromFloat(1.0).Sub(NewFromFloat(0.5).Mul(zz)).Add(w) - } - if sign { - y = y.Neg() - } - return y -} - -var _tanP = [...]Decimal{ - NewFromFloat(-1.30936939181383777646e+4), // 0xc0c992d8d24f3f38 - NewFromFloat(1.15351664838587416140e+6), // 0x413199eca5fc9ddd - NewFromFloat(-1.79565251976484877988e+7), // 0xc1711fead3299176 -} -var _tanQ = [...]Decimal{ - NewFromFloat(1.00000000000000000000e+0), - NewFromFloat(1.36812963470692954678e+4), //0x40cab8a5eeb36572 - NewFromFloat(-1.32089234440210967447e+6), //0xc13427bc582abc96 - NewFromFloat(2.50083801823357915839e+7), //0x4177d98fc2ead8ef - NewFromFloat(-5.38695755929454629881e+7), //0xc189afe03cbe5a31 -} - -// Tan returns the tangent of the radian argument x. -func (d Decimal) Tan() Decimal { - - PI4A := NewFromFloat(7.85398125648498535156e-1) // 0x3fe921fb40000000, Pi/4 split into three parts - PI4B := NewFromFloat(3.77489470793079817668e-8) // 0x3e64442d00000000, - PI4C := NewFromFloat(2.69515142907905952645e-15) // 0x3ce8469898cc5170, - M4PI := NewFromFloat(1.273239544735162542821171882678754627704620361328125) // 4/pi - - if d.Equal(NewFromFloat(0.0)) { - return d - } - - // make argument positive but save the sign - sign := false - if d.LessThan(NewFromFloat(0.0)) { - d = d.Neg() - sign = true - } - - j := d.Mul(M4PI).IntPart() // integer part of x/(Pi/4), as integer for tests on the phase angle - y := NewFromFloat(float64(j)) // integer part of x/(Pi/4), as float - - // map zeros to origin - if j&1 == 1 { - j++ - y = y.Add(NewFromFloat(1.0)) - } - - z := d.Sub(y.Mul(PI4A)).Sub(y.Mul(PI4B)).Sub(y.Mul(PI4C)) // Extended precision modular arithmetic - zz := z.Mul(z) - - if zz.GreaterThan(NewFromFloat(1e-14)) { - w := zz.Mul(_tanP[0].Mul(zz).Add(_tanP[1]).Mul(zz).Add(_tanP[2])) - x := zz.Add(_tanQ[1]).Mul(zz).Add(_tanQ[2]).Mul(zz).Add(_tanQ[3]).Mul(zz).Add(_tanQ[4]) - y = z.Add(z.Mul(w.Div(x))) - } else { - y = z - } - if j&2 == 2 { - y = NewFromFloat(-1.0).Div(y) - } - if sign { - y = y.Neg() - } - return y -} diff --git a/vendor/github.com/shopspring/decimal/rounding.go b/vendor/github.com/shopspring/decimal/rounding.go deleted file mode 100644 index d4b0cd0079..0000000000 --- a/vendor/github.com/shopspring/decimal/rounding.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Multiprecision decimal numbers. -// For floating-point formatting only; not general purpose. -// Only operations are assign and (binary) left/right shift. -// Can do binary floating point in multiprecision decimal precisely -// because 2 divides 10; cannot do decimal floating point -// in multiprecision binary precisely. - -package decimal - -type floatInfo struct { - mantbits uint - expbits uint - bias int -} - -var float32info = floatInfo{23, 8, -127} -var float64info = floatInfo{52, 11, -1023} - -// roundShortest rounds d (= mant * 2^exp) to the shortest number of digits -// that will let the original floating point value be precisely reconstructed. -func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) { - // If mantissa is zero, the number is zero; stop now. - if mant == 0 { - d.nd = 0 - return - } - - // Compute upper and lower such that any decimal number - // between upper and lower (possibly inclusive) - // will round to the original floating point number. - - // We may see at once that the number is already shortest. - // - // Suppose d is not denormal, so that 2^exp <= d < 10^dp. - // The closest shorter number is at least 10^(dp-nd) away. - // The lower/upper bounds computed below are at distance - // at most 2^(exp-mantbits). - // - // So the number is already shortest if 10^(dp-nd) > 2^(exp-mantbits), - // or equivalently log2(10)*(dp-nd) > exp-mantbits. - // It is true if 332/100*(dp-nd) >= exp-mantbits (log2(10) > 3.32). - minexp := flt.bias + 1 // minimum possible exponent - if exp > minexp && 332*(d.dp-d.nd) >= 100*(exp-int(flt.mantbits)) { - // The number is already shortest. - return - } - - // d = mant << (exp - mantbits) - // Next highest floating point number is mant+1 << exp-mantbits. - // Our upper bound is halfway between, mant*2+1 << exp-mantbits-1. - upper := new(decimal) - upper.Assign(mant*2 + 1) - upper.Shift(exp - int(flt.mantbits) - 1) - - // d = mant << (exp - mantbits) - // Next lowest floating point number is mant-1 << exp-mantbits, - // unless mant-1 drops the significant bit and exp is not the minimum exp, - // in which case the next lowest is mant*2-1 << exp-mantbits-1. - // Either way, call it mantlo << explo-mantbits. - // Our lower bound is halfway between, mantlo*2+1 << explo-mantbits-1. - var mantlo uint64 - var explo int - if mant > 1<= d.nd { - break - } - li := ui - upper.dp + lower.dp - l := byte('0') // lower digit - if li >= 0 && li < lower.nd { - l = lower.d[li] - } - m := byte('0') // middle digit - if mi >= 0 { - m = d.d[mi] - } - u := byte('0') // upper digit - if ui < upper.nd { - u = upper.d[ui] - } - - // Okay to round down (truncate) if lower has a different digit - // or if lower is inclusive and is exactly the result of rounding - // down (i.e., and we have reached the final digit of lower). - okdown := l != m || inclusive && li+1 == lower.nd - - switch { - case upperdelta == 0 && m+1 < u: - // Example: - // m = 12345xxx - // u = 12347xxx - upperdelta = 2 - case upperdelta == 0 && m != u: - // Example: - // m = 12345xxx - // u = 12346xxx - upperdelta = 1 - case upperdelta == 1 && (m != '9' || u != '0'): - // Example: - // m = 1234598x - // u = 1234600x - upperdelta = 2 - } - // Okay to round up if upper has a different digit and either upper - // is inclusive or upper is bigger than the result of rounding up. - okup := upperdelta > 0 && (inclusive || upperdelta > 1 || ui+1 < upper.nd) - - // If it's okay to do either, then round to the nearest one. - // If it's okay to do only one, do it. - switch { - case okdown && okup: - d.Round(mi + 1) - return - case okdown: - d.RoundDown(mi + 1) - return - case okup: - d.RoundUp(mi + 1) - return - } - } -} diff --git a/vendor/go.opentelemetry.io/otel/LICENSE b/vendor/go.opentelemetry.io/otel/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/attribute/doc.go b/vendor/go.opentelemetry.io/otel/attribute/doc.go deleted file mode 100644 index dafe7424df..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package attribute provides key and value attributes. -package attribute // import "go.opentelemetry.io/otel/attribute" diff --git a/vendor/go.opentelemetry.io/otel/attribute/encoder.go b/vendor/go.opentelemetry.io/otel/attribute/encoder.go deleted file mode 100644 index dae1d8f61f..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/encoder.go +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "bytes" - "sync" - "sync/atomic" -) - -type ( - // Encoder is a mechanism for serializing an attribute set into a specific - // string representation that supports caching, to avoid repeated - // serialization. An example could be an exporter encoding the attribute - // set into a wire representation. - Encoder interface { - // Encode returns the serialized encoding of the attribute set using - // its Iterator. This result may be cached by a attribute.Set. - Encode(iterator Iterator) string - - // ID returns a value that is unique for each class of attribute - // encoder. Attribute encoders allocate these using `NewEncoderID`. - ID() EncoderID - } - - // EncoderID is used to identify distinct Encoder - // implementations, for caching encoded results. - EncoderID struct { - value uint64 - } - - // defaultAttrEncoder uses a sync.Pool of buffers to reduce the number of - // allocations used in encoding attributes. This implementation encodes a - // comma-separated list of key=value, with '/'-escaping of '=', ',', and - // '\'. - defaultAttrEncoder struct { - // pool is a pool of attribute set builders. The buffers in this pool - // grow to a size that most attribute encodings will not allocate new - // memory. - pool sync.Pool // *bytes.Buffer - } -) - -// escapeChar is used to ensure uniqueness of the attribute encoding where -// keys or values contain either '=' or ','. Since there is no parser needed -// for this encoding and its only requirement is to be unique, this choice is -// arbitrary. Users will see these in some exporters (e.g., stdout), so the -// backslash ('\') is used as a conventional choice. -const escapeChar = '\\' - -var ( - _ Encoder = &defaultAttrEncoder{} - - // encoderIDCounter is for generating IDs for other attribute encoders. - encoderIDCounter uint64 - - defaultEncoderOnce sync.Once - defaultEncoderID = NewEncoderID() - defaultEncoderInstance *defaultAttrEncoder -) - -// NewEncoderID returns a unique attribute encoder ID. It should be called -// once per each type of attribute encoder. Preferably in init() or in var -// definition. -func NewEncoderID() EncoderID { - return EncoderID{value: atomic.AddUint64(&encoderIDCounter, 1)} -} - -// DefaultEncoder returns an attribute encoder that encodes attributes in such -// a way that each escaped attribute's key is followed by an equal sign and -// then by an escaped attribute's value. All key-value pairs are separated by -// a comma. -// -// Escaping is done by prepending a backslash before either a backslash, equal -// sign or a comma. -func DefaultEncoder() Encoder { - defaultEncoderOnce.Do(func() { - defaultEncoderInstance = &defaultAttrEncoder{ - pool: sync.Pool{ - New: func() interface{} { - return &bytes.Buffer{} - }, - }, - } - }) - return defaultEncoderInstance -} - -// Encode is a part of an implementation of the AttributeEncoder interface. -func (d *defaultAttrEncoder) Encode(iter Iterator) string { - buf := d.pool.Get().(*bytes.Buffer) - defer d.pool.Put(buf) - buf.Reset() - - for iter.Next() { - i, keyValue := iter.IndexedAttribute() - if i > 0 { - _, _ = buf.WriteRune(',') - } - copyAndEscape(buf, string(keyValue.Key)) - - _, _ = buf.WriteRune('=') - - if keyValue.Value.Type() == STRING { - copyAndEscape(buf, keyValue.Value.AsString()) - } else { - _, _ = buf.WriteString(keyValue.Value.Emit()) - } - } - return buf.String() -} - -// ID is a part of an implementation of the AttributeEncoder interface. -func (*defaultAttrEncoder) ID() EncoderID { - return defaultEncoderID -} - -// copyAndEscape escapes `=`, `,` and its own escape character (`\`), -// making the default encoding unique. -func copyAndEscape(buf *bytes.Buffer, val string) { - for _, ch := range val { - switch ch { - case '=', ',', escapeChar: - buf.WriteRune(escapeChar) - } - buf.WriteRune(ch) - } -} - -// Valid returns true if this encoder ID was allocated by -// `NewEncoderID`. Invalid encoder IDs will not be cached. -func (id EncoderID) Valid() bool { - return id.value != 0 -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/iterator.go b/vendor/go.opentelemetry.io/otel/attribute/iterator.go deleted file mode 100644 index 841b271fb7..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/iterator.go +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -// Iterator allows iterating over the set of attributes in order, sorted by -// key. -type Iterator struct { - storage *Set - idx int -} - -// MergeIterator supports iterating over two sets of attributes while -// eliminating duplicate values from the combined set. The first iterator -// value takes precedence. -type MergeIterator struct { - one oneIterator - two oneIterator - current KeyValue -} - -type oneIterator struct { - iter Iterator - done bool - attr KeyValue -} - -// Next moves the iterator to the next position. Returns false if there are no -// more attributes. -func (i *Iterator) Next() bool { - i.idx++ - return i.idx < i.Len() -} - -// Label returns current KeyValue. Must be called only after Next returns -// true. -// -// Deprecated: Use Attribute instead. -func (i *Iterator) Label() KeyValue { - return i.Attribute() -} - -// Attribute returns the current KeyValue of the Iterator. It must be called -// only after Next returns true. -func (i *Iterator) Attribute() KeyValue { - kv, _ := i.storage.Get(i.idx) - return kv -} - -// IndexedLabel returns current index and attribute. Must be called only -// after Next returns true. -// -// Deprecated: Use IndexedAttribute instead. -func (i *Iterator) IndexedLabel() (int, KeyValue) { - return i.idx, i.Attribute() -} - -// IndexedAttribute returns current index and attribute. Must be called only -// after Next returns true. -func (i *Iterator) IndexedAttribute() (int, KeyValue) { - return i.idx, i.Attribute() -} - -// Len returns a number of attributes in the iterated set. -func (i *Iterator) Len() int { - return i.storage.Len() -} - -// ToSlice is a convenience function that creates a slice of attributes from -// the passed iterator. The iterator is set up to start from the beginning -// before creating the slice. -func (i *Iterator) ToSlice() []KeyValue { - l := i.Len() - if l == 0 { - return nil - } - i.idx = -1 - slice := make([]KeyValue, 0, l) - for i.Next() { - slice = append(slice, i.Attribute()) - } - return slice -} - -// NewMergeIterator returns a MergeIterator for merging two attribute sets. -// Duplicates are resolved by taking the value from the first set. -func NewMergeIterator(s1, s2 *Set) MergeIterator { - mi := MergeIterator{ - one: makeOne(s1.Iter()), - two: makeOne(s2.Iter()), - } - return mi -} - -func makeOne(iter Iterator) oneIterator { - oi := oneIterator{ - iter: iter, - } - oi.advance() - return oi -} - -func (oi *oneIterator) advance() { - if oi.done = !oi.iter.Next(); !oi.done { - oi.attr = oi.iter.Attribute() - } -} - -// Next returns true if there is another attribute available. -func (m *MergeIterator) Next() bool { - if m.one.done && m.two.done { - return false - } - if m.one.done { - m.current = m.two.attr - m.two.advance() - return true - } - if m.two.done { - m.current = m.one.attr - m.one.advance() - return true - } - if m.one.attr.Key == m.two.attr.Key { - m.current = m.one.attr // first iterator attribute value wins - m.one.advance() - m.two.advance() - return true - } - if m.one.attr.Key < m.two.attr.Key { - m.current = m.one.attr - m.one.advance() - return true - } - m.current = m.two.attr - m.two.advance() - return true -} - -// Label returns the current value after Next() returns true. -// -// Deprecated: Use Attribute instead. -func (m *MergeIterator) Label() KeyValue { - return m.current -} - -// Attribute returns the current value after Next() returns true. -func (m *MergeIterator) Attribute() KeyValue { - return m.current -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/key.go b/vendor/go.opentelemetry.io/otel/attribute/key.go deleted file mode 100644 index 0656a04e43..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/key.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -// Key represents the key part in key-value pairs. It's a string. The -// allowed character set in the key depends on the use of the key. -type Key string - -// Bool creates a KeyValue instance with a BOOL Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Bool(name, value). -func (k Key) Bool(v bool) KeyValue { - return KeyValue{ - Key: k, - Value: BoolValue(v), - } -} - -// BoolSlice creates a KeyValue instance with a BOOLSLICE Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- BoolSlice(name, value). -func (k Key) BoolSlice(v []bool) KeyValue { - return KeyValue{ - Key: k, - Value: BoolSliceValue(v), - } -} - -// Int creates a KeyValue instance with an INT64 Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Int(name, value). -func (k Key) Int(v int) KeyValue { - return KeyValue{ - Key: k, - Value: IntValue(v), - } -} - -// IntSlice creates a KeyValue instance with an INT64SLICE Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- IntSlice(name, value). -func (k Key) IntSlice(v []int) KeyValue { - return KeyValue{ - Key: k, - Value: IntSliceValue(v), - } -} - -// Int64 creates a KeyValue instance with an INT64 Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Int64(name, value). -func (k Key) Int64(v int64) KeyValue { - return KeyValue{ - Key: k, - Value: Int64Value(v), - } -} - -// Int64Slice creates a KeyValue instance with an INT64SLICE Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Int64Slice(name, value). -func (k Key) Int64Slice(v []int64) KeyValue { - return KeyValue{ - Key: k, - Value: Int64SliceValue(v), - } -} - -// Float64 creates a KeyValue instance with a FLOAT64 Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Float64(name, value). -func (k Key) Float64(v float64) KeyValue { - return KeyValue{ - Key: k, - Value: Float64Value(v), - } -} - -// Float64Slice creates a KeyValue instance with a FLOAT64SLICE Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- Float64(name, value). -func (k Key) Float64Slice(v []float64) KeyValue { - return KeyValue{ - Key: k, - Value: Float64SliceValue(v), - } -} - -// String creates a KeyValue instance with a STRING Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- String(name, value). -func (k Key) String(v string) KeyValue { - return KeyValue{ - Key: k, - Value: StringValue(v), - } -} - -// StringSlice creates a KeyValue instance with a STRINGSLICE Value. -// -// If creating both a key and value at the same time, use the provided -// convenience function instead -- StringSlice(name, value). -func (k Key) StringSlice(v []string) KeyValue { - return KeyValue{ - Key: k, - Value: StringSliceValue(v), - } -} - -// Defined returns true for non-empty keys. -func (k Key) Defined() bool { - return len(k) != 0 -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/kv.go b/vendor/go.opentelemetry.io/otel/attribute/kv.go deleted file mode 100644 index 1ddf3ce058..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/kv.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "fmt" -) - -// KeyValue holds a key and value pair. -type KeyValue struct { - Key Key - Value Value -} - -// Valid returns if kv is a valid OpenTelemetry attribute. -func (kv KeyValue) Valid() bool { - return kv.Key.Defined() && kv.Value.Type() != INVALID -} - -// Bool creates a KeyValue with a BOOL Value type. -func Bool(k string, v bool) KeyValue { - return Key(k).Bool(v) -} - -// BoolSlice creates a KeyValue with a BOOLSLICE Value type. -func BoolSlice(k string, v []bool) KeyValue { - return Key(k).BoolSlice(v) -} - -// Int creates a KeyValue with an INT64 Value type. -func Int(k string, v int) KeyValue { - return Key(k).Int(v) -} - -// IntSlice creates a KeyValue with an INT64SLICE Value type. -func IntSlice(k string, v []int) KeyValue { - return Key(k).IntSlice(v) -} - -// Int64 creates a KeyValue with an INT64 Value type. -func Int64(k string, v int64) KeyValue { - return Key(k).Int64(v) -} - -// Int64Slice creates a KeyValue with an INT64SLICE Value type. -func Int64Slice(k string, v []int64) KeyValue { - return Key(k).Int64Slice(v) -} - -// Float64 creates a KeyValue with a FLOAT64 Value type. -func Float64(k string, v float64) KeyValue { - return Key(k).Float64(v) -} - -// Float64Slice creates a KeyValue with a FLOAT64SLICE Value type. -func Float64Slice(k string, v []float64) KeyValue { - return Key(k).Float64Slice(v) -} - -// String creates a KeyValue with a STRING Value type. -func String(k, v string) KeyValue { - return Key(k).String(v) -} - -// StringSlice creates a KeyValue with a STRINGSLICE Value type. -func StringSlice(k string, v []string) KeyValue { - return Key(k).StringSlice(v) -} - -// Stringer creates a new key-value pair with a passed name and a string -// value generated by the passed Stringer interface. -func Stringer(k string, v fmt.Stringer) KeyValue { - return Key(k).String(v.String()) -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/set.go b/vendor/go.opentelemetry.io/otel/attribute/set.go deleted file mode 100644 index 5c24700866..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/set.go +++ /dev/null @@ -1,424 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "encoding/json" - "reflect" - "sort" -) - -type ( - // Set is the representation for a distinct attribute set. It manages an - // immutable set of attributes, with an internal cache for storing - // attribute encodings. - // - // This type supports the Equivalent method of comparison using values of - // type Distinct. - Set struct { - equivalent Distinct - } - - // Distinct wraps a variable-size array of KeyValue, constructed with keys - // in sorted order. This can be used as a map key or for equality checking - // between Sets. - Distinct struct { - iface interface{} - } - - // Filter supports removing certain attributes from attribute sets. When - // the filter returns true, the attribute will be kept in the filtered - // attribute set. When the filter returns false, the attribute is excluded - // from the filtered attribute set, and the attribute instead appears in - // the removed list of excluded attributes. - Filter func(KeyValue) bool - - // Sortable implements sort.Interface, used for sorting KeyValue. This is - // an exported type to support a memory optimization. A pointer to one of - // these is needed for the call to sort.Stable(), which the caller may - // provide in order to avoid an allocation. See NewSetWithSortable(). - Sortable []KeyValue -) - -var ( - // keyValueType is used in computeDistinctReflect. - keyValueType = reflect.TypeOf(KeyValue{}) - - // emptySet is returned for empty attribute sets. - emptySet = &Set{ - equivalent: Distinct{ - iface: [0]KeyValue{}, - }, - } -) - -// EmptySet returns a reference to a Set with no elements. -// -// This is a convenience provided for optimized calling utility. -func EmptySet() *Set { - return emptySet -} - -// reflect abbreviates reflect.ValueOf. -func (d Distinct) reflect() reflect.Value { - return reflect.ValueOf(d.iface) -} - -// Valid returns true if this value refers to a valid Set. -func (d Distinct) Valid() bool { - return d.iface != nil -} - -// Len returns the number of attributes in this set. -func (l *Set) Len() int { - if l == nil || !l.equivalent.Valid() { - return 0 - } - return l.equivalent.reflect().Len() -} - -// Get returns the KeyValue at ordered position idx in this set. -func (l *Set) Get(idx int) (KeyValue, bool) { - if l == nil { - return KeyValue{}, false - } - value := l.equivalent.reflect() - - if idx >= 0 && idx < value.Len() { - // Note: The Go compiler successfully avoids an allocation for - // the interface{} conversion here: - return value.Index(idx).Interface().(KeyValue), true - } - - return KeyValue{}, false -} - -// Value returns the value of a specified key in this set. -func (l *Set) Value(k Key) (Value, bool) { - if l == nil { - return Value{}, false - } - rValue := l.equivalent.reflect() - vlen := rValue.Len() - - idx := sort.Search(vlen, func(idx int) bool { - return rValue.Index(idx).Interface().(KeyValue).Key >= k - }) - if idx >= vlen { - return Value{}, false - } - keyValue := rValue.Index(idx).Interface().(KeyValue) - if k == keyValue.Key { - return keyValue.Value, true - } - return Value{}, false -} - -// HasValue tests whether a key is defined in this set. -func (l *Set) HasValue(k Key) bool { - if l == nil { - return false - } - _, ok := l.Value(k) - return ok -} - -// Iter returns an iterator for visiting the attributes in this set. -func (l *Set) Iter() Iterator { - return Iterator{ - storage: l, - idx: -1, - } -} - -// ToSlice returns the set of attributes belonging to this set, sorted, where -// keys appear no more than once. -func (l *Set) ToSlice() []KeyValue { - iter := l.Iter() - return iter.ToSlice() -} - -// Equivalent returns a value that may be used as a map key. The Distinct type -// guarantees that the result will equal the equivalent. Distinct value of any -// attribute set with the same elements as this, where sets are made unique by -// choosing the last value in the input for any given key. -func (l *Set) Equivalent() Distinct { - if l == nil || !l.equivalent.Valid() { - return emptySet.equivalent - } - return l.equivalent -} - -// Equals returns true if the argument set is equivalent to this set. -func (l *Set) Equals(o *Set) bool { - return l.Equivalent() == o.Equivalent() -} - -// Encoded returns the encoded form of this set, according to encoder. -func (l *Set) Encoded(encoder Encoder) string { - if l == nil || encoder == nil { - return "" - } - - return encoder.Encode(l.Iter()) -} - -func empty() Set { - return Set{ - equivalent: emptySet.equivalent, - } -} - -// NewSet returns a new Set. See the documentation for -// NewSetWithSortableFiltered for more details. -// -// Except for empty sets, this method adds an additional allocation compared -// with calls that include a Sortable. -func NewSet(kvs ...KeyValue) Set { - // Check for empty set. - if len(kvs) == 0 { - return empty() - } - s, _ := NewSetWithSortableFiltered(kvs, new(Sortable), nil) - return s -} - -// NewSetWithSortable returns a new Set. See the documentation for -// NewSetWithSortableFiltered for more details. -// -// This call includes a Sortable option as a memory optimization. -func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set { - // Check for empty set. - if len(kvs) == 0 { - return empty() - } - s, _ := NewSetWithSortableFiltered(kvs, tmp, nil) - return s -} - -// NewSetWithFiltered returns a new Set. See the documentation for -// NewSetWithSortableFiltered for more details. -// -// This call includes a Filter to include/exclude attribute keys from the -// return value. Excluded keys are returned as a slice of attribute values. -func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) { - // Check for empty set. - if len(kvs) == 0 { - return empty(), nil - } - return NewSetWithSortableFiltered(kvs, new(Sortable), filter) -} - -// NewSetWithSortableFiltered returns a new Set. -// -// Duplicate keys are eliminated by taking the last value. This -// re-orders the input slice so that unique last-values are contiguous -// at the end of the slice. -// -// This ensures the following: -// -// - Last-value-wins semantics -// - Caller sees the reordering, but doesn't lose values -// - Repeated call preserve last-value wins. -// -// Note that methods are defined on Set, although this returns Set. Callers -// can avoid memory allocations by: -// -// - allocating a Sortable for use as a temporary in this method -// - allocating a Set for storing the return value of this constructor. -// -// The result maintains a cache of encoded attributes, by attribute.EncoderID. -// This value should not be copied after its first use. -// -// The second []KeyValue return value is a list of attributes that were -// excluded by the Filter (if non-nil). -func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (Set, []KeyValue) { - // Check for empty set. - if len(kvs) == 0 { - return empty(), nil - } - - *tmp = kvs - - // Stable sort so the following de-duplication can implement - // last-value-wins semantics. - sort.Stable(tmp) - - *tmp = nil - - position := len(kvs) - 1 - offset := position - 1 - - // The requirements stated above require that the stable - // result be placed in the end of the input slice, while - // overwritten values are swapped to the beginning. - // - // De-duplicate with last-value-wins semantics. Preserve - // duplicate values at the beginning of the input slice. - for ; offset >= 0; offset-- { - if kvs[offset].Key == kvs[position].Key { - continue - } - position-- - kvs[offset], kvs[position] = kvs[position], kvs[offset] - } - if filter != nil { - return filterSet(kvs[position:], filter) - } - return Set{ - equivalent: computeDistinct(kvs[position:]), - }, nil -} - -// filterSet reorders kvs so that included keys are contiguous at the end of -// the slice, while excluded keys precede the included keys. -func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) { - var excluded []KeyValue - - // Move attributes that do not match the filter so they're adjacent before - // calling computeDistinct(). - distinctPosition := len(kvs) - - // Swap indistinct keys forward and distinct keys toward the - // end of the slice. - offset := len(kvs) - 1 - for ; offset >= 0; offset-- { - if filter(kvs[offset]) { - distinctPosition-- - kvs[offset], kvs[distinctPosition] = kvs[distinctPosition], kvs[offset] - continue - } - } - excluded = kvs[:distinctPosition] - - return Set{ - equivalent: computeDistinct(kvs[distinctPosition:]), - }, excluded -} - -// Filter returns a filtered copy of this Set. See the documentation for -// NewSetWithSortableFiltered for more details. -func (l *Set) Filter(re Filter) (Set, []KeyValue) { - if re == nil { - return Set{ - equivalent: l.equivalent, - }, nil - } - - // Note: This could be refactored to avoid the temporary slice - // allocation, if it proves to be expensive. - return filterSet(l.ToSlice(), re) -} - -// computeDistinct returns a Distinct using either the fixed- or -// reflect-oriented code path, depending on the size of the input. The input -// slice is assumed to already be sorted and de-duplicated. -func computeDistinct(kvs []KeyValue) Distinct { - iface := computeDistinctFixed(kvs) - if iface == nil { - iface = computeDistinctReflect(kvs) - } - return Distinct{ - iface: iface, - } -} - -// computeDistinctFixed computes a Distinct for small slices. It returns nil -// if the input is too large for this code path. -func computeDistinctFixed(kvs []KeyValue) interface{} { - switch len(kvs) { - case 1: - ptr := new([1]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 2: - ptr := new([2]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 3: - ptr := new([3]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 4: - ptr := new([4]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 5: - ptr := new([5]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 6: - ptr := new([6]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 7: - ptr := new([7]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 8: - ptr := new([8]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 9: - ptr := new([9]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - case 10: - ptr := new([10]KeyValue) - copy((*ptr)[:], kvs) - return *ptr - default: - return nil - } -} - -// computeDistinctReflect computes a Distinct using reflection, works for any -// size input. -func computeDistinctReflect(kvs []KeyValue) interface{} { - at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem() - for i, keyValue := range kvs { - *(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue - } - return at.Interface() -} - -// MarshalJSON returns the JSON encoding of the Set. -func (l *Set) MarshalJSON() ([]byte, error) { - return json.Marshal(l.equivalent.iface) -} - -// MarshalLog is the marshaling function used by the logging system to represent this exporter. -func (l Set) MarshalLog() interface{} { - kvs := make(map[string]string) - for _, kv := range l.ToSlice() { - kvs[string(kv.Key)] = kv.Value.Emit() - } - return kvs -} - -// Len implements sort.Interface. -func (l *Sortable) Len() int { - return len(*l) -} - -// Swap implements sort.Interface. -func (l *Sortable) Swap(i, j int) { - (*l)[i], (*l)[j] = (*l)[j], (*l)[i] -} - -// Less implements sort.Interface. -func (l *Sortable) Less(i, j int) bool { - return (*l)[i].Key < (*l)[j].Key -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/type_string.go b/vendor/go.opentelemetry.io/otel/attribute/type_string.go deleted file mode 100644 index e584b24776..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/type_string.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by "stringer -type=Type"; DO NOT EDIT. - -package attribute - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[INVALID-0] - _ = x[BOOL-1] - _ = x[INT64-2] - _ = x[FLOAT64-3] - _ = x[STRING-4] - _ = x[BOOLSLICE-5] - _ = x[INT64SLICE-6] - _ = x[FLOAT64SLICE-7] - _ = x[STRINGSLICE-8] -} - -const _Type_name = "INVALIDBOOLINT64FLOAT64STRINGBOOLSLICEINT64SLICEFLOAT64SLICESTRINGSLICE" - -var _Type_index = [...]uint8{0, 7, 11, 16, 23, 29, 38, 48, 60, 71} - -func (i Type) String() string { - if i < 0 || i >= Type(len(_Type_index)-1) { - return "Type(" + strconv.FormatInt(int64(i), 10) + ")" - } - return _Type_name[_Type_index[i]:_Type_index[i+1]] -} diff --git a/vendor/go.opentelemetry.io/otel/attribute/value.go b/vendor/go.opentelemetry.io/otel/attribute/value.go deleted file mode 100644 index 6ec5cb290d..0000000000 --- a/vendor/go.opentelemetry.io/otel/attribute/value.go +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package attribute // import "go.opentelemetry.io/otel/attribute" - -import ( - "encoding/json" - "fmt" - "strconv" - - "go.opentelemetry.io/otel/internal" -) - -//go:generate stringer -type=Type - -// Type describes the type of the data Value holds. -type Type int - -// Value represents the value part in key-value pairs. -type Value struct { - vtype Type - numeric uint64 - stringly string - slice interface{} -} - -const ( - // INVALID is used for a Value with no value set. - INVALID Type = iota - // BOOL is a boolean Type Value. - BOOL - // INT64 is a 64-bit signed integral Type Value. - INT64 - // FLOAT64 is a 64-bit floating point Type Value. - FLOAT64 - // STRING is a string Type Value. - STRING - // BOOLSLICE is a slice of booleans Type Value. - BOOLSLICE - // INT64SLICE is a slice of 64-bit signed integral numbers Type Value. - INT64SLICE - // FLOAT64SLICE is a slice of 64-bit floating point numbers Type Value. - FLOAT64SLICE - // STRINGSLICE is a slice of strings Type Value. - STRINGSLICE -) - -// BoolValue creates a BOOL Value. -func BoolValue(v bool) Value { - return Value{ - vtype: BOOL, - numeric: internal.BoolToRaw(v), - } -} - -// BoolSliceValue creates a BOOLSLICE Value. -func BoolSliceValue(v []bool) Value { - cp := make([]bool, len(v)) - copy(cp, v) - return Value{ - vtype: BOOLSLICE, - slice: &cp, - } -} - -// IntValue creates an INT64 Value. -func IntValue(v int) Value { - return Int64Value(int64(v)) -} - -// IntSliceValue creates an INTSLICE Value. -func IntSliceValue(v []int) Value { - cp := make([]int64, 0, len(v)) - for _, i := range v { - cp = append(cp, int64(i)) - } - return Value{ - vtype: INT64SLICE, - slice: &cp, - } -} - -// Int64Value creates an INT64 Value. -func Int64Value(v int64) Value { - return Value{ - vtype: INT64, - numeric: internal.Int64ToRaw(v), - } -} - -// Int64SliceValue creates an INT64SLICE Value. -func Int64SliceValue(v []int64) Value { - cp := make([]int64, len(v)) - copy(cp, v) - return Value{ - vtype: INT64SLICE, - slice: &cp, - } -} - -// Float64Value creates a FLOAT64 Value. -func Float64Value(v float64) Value { - return Value{ - vtype: FLOAT64, - numeric: internal.Float64ToRaw(v), - } -} - -// Float64SliceValue creates a FLOAT64SLICE Value. -func Float64SliceValue(v []float64) Value { - cp := make([]float64, len(v)) - copy(cp, v) - return Value{ - vtype: FLOAT64SLICE, - slice: &cp, - } -} - -// StringValue creates a STRING Value. -func StringValue(v string) Value { - return Value{ - vtype: STRING, - stringly: v, - } -} - -// StringSliceValue creates a STRINGSLICE Value. -func StringSliceValue(v []string) Value { - cp := make([]string, len(v)) - copy(cp, v) - return Value{ - vtype: STRINGSLICE, - slice: &cp, - } -} - -// Type returns a type of the Value. -func (v Value) Type() Type { - return v.vtype -} - -// AsBool returns the bool value. Make sure that the Value's type is -// BOOL. -func (v Value) AsBool() bool { - return internal.RawToBool(v.numeric) -} - -// AsBoolSlice returns the []bool value. Make sure that the Value's type is -// BOOLSLICE. -func (v Value) AsBoolSlice() []bool { - if s, ok := v.slice.(*[]bool); ok { - return *s - } - return nil -} - -// AsInt64 returns the int64 value. Make sure that the Value's type is -// INT64. -func (v Value) AsInt64() int64 { - return internal.RawToInt64(v.numeric) -} - -// AsInt64Slice returns the []int64 value. Make sure that the Value's type is -// INT64SLICE. -func (v Value) AsInt64Slice() []int64 { - if s, ok := v.slice.(*[]int64); ok { - return *s - } - return nil -} - -// AsFloat64 returns the float64 value. Make sure that the Value's -// type is FLOAT64. -func (v Value) AsFloat64() float64 { - return internal.RawToFloat64(v.numeric) -} - -// AsFloat64Slice returns the []float64 value. Make sure that the Value's type is -// FLOAT64SLICE. -func (v Value) AsFloat64Slice() []float64 { - if s, ok := v.slice.(*[]float64); ok { - return *s - } - return nil -} - -// AsString returns the string value. Make sure that the Value's type -// is STRING. -func (v Value) AsString() string { - return v.stringly -} - -// AsStringSlice returns the []string value. Make sure that the Value's type is -// STRINGSLICE. -func (v Value) AsStringSlice() []string { - if s, ok := v.slice.(*[]string); ok { - return *s - } - return nil -} - -type unknownValueType struct{} - -// AsInterface returns Value's data as interface{}. -func (v Value) AsInterface() interface{} { - switch v.Type() { - case BOOL: - return v.AsBool() - case BOOLSLICE: - return v.AsBoolSlice() - case INT64: - return v.AsInt64() - case INT64SLICE: - return v.AsInt64Slice() - case FLOAT64: - return v.AsFloat64() - case FLOAT64SLICE: - return v.AsFloat64Slice() - case STRING: - return v.stringly - case STRINGSLICE: - return v.AsStringSlice() - } - return unknownValueType{} -} - -// Emit returns a string representation of Value's data. -func (v Value) Emit() string { - switch v.Type() { - case BOOLSLICE: - return fmt.Sprint(*(v.slice.(*[]bool))) - case BOOL: - return strconv.FormatBool(v.AsBool()) - case INT64SLICE: - return fmt.Sprint(*(v.slice.(*[]int64))) - case INT64: - return strconv.FormatInt(v.AsInt64(), 10) - case FLOAT64SLICE: - return fmt.Sprint(*(v.slice.(*[]float64))) - case FLOAT64: - return fmt.Sprint(v.AsFloat64()) - case STRINGSLICE: - return fmt.Sprint(*(v.slice.(*[]string))) - case STRING: - return v.stringly - default: - return "unknown" - } -} - -// MarshalJSON returns the JSON encoding of the Value. -func (v Value) MarshalJSON() ([]byte, error) { - var jsonVal struct { - Type string - Value interface{} - } - jsonVal.Type = v.Type().String() - jsonVal.Value = v.AsInterface() - return json.Marshal(jsonVal) -} diff --git a/vendor/go.opentelemetry.io/otel/codes/codes.go b/vendor/go.opentelemetry.io/otel/codes/codes.go deleted file mode 100644 index 064a9279fd..0000000000 --- a/vendor/go.opentelemetry.io/otel/codes/codes.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package codes // import "go.opentelemetry.io/otel/codes" - -import ( - "encoding/json" - "fmt" - "strconv" -) - -const ( - // Unset is the default status code. - Unset Code = 0 - // Error indicates the operation contains an error. - Error Code = 1 - // Ok indicates operation has been validated by an Application developers - // or Operator to have completed successfully, or contain no error. - Ok Code = 2 - - maxCode = 3 -) - -// Code is an 32-bit representation of a status state. -type Code uint32 - -var codeToStr = map[Code]string{ - Unset: "Unset", - Error: "Error", - Ok: "Ok", -} - -var strToCode = map[string]Code{ - `"Unset"`: Unset, - `"Error"`: Error, - `"Ok"`: Ok, -} - -// String returns the Code as a string. -func (c Code) String() string { - return codeToStr[c] -} - -// UnmarshalJSON unmarshals b into the Code. -// -// This is based on the functionality in the gRPC codes package: -// https://github.com/grpc/grpc-go/blob/bb64fee312b46ebee26be43364a7a966033521b1/codes/codes.go#L218-L244 -func (c *Code) UnmarshalJSON(b []byte) error { - // From json.Unmarshaler: By convention, to approximate the behavior of - // Unmarshal itself, Unmarshalers implement UnmarshalJSON([]byte("null")) as - // a no-op. - if string(b) == "null" { - return nil - } - if c == nil { - return fmt.Errorf("nil receiver passed to UnmarshalJSON") - } - - var x interface{} - if err := json.Unmarshal(b, &x); err != nil { - return err - } - switch x.(type) { - case string: - if jc, ok := strToCode[string(b)]; ok { - *c = jc - return nil - } - return fmt.Errorf("invalid code: %q", string(b)) - case float64: - if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil { - if ci >= maxCode { - return fmt.Errorf("invalid code: %q", ci) - } - - *c = Code(ci) - return nil - } - return fmt.Errorf("invalid code: %q", string(b)) - default: - return fmt.Errorf("invalid code: %q", string(b)) - } -} - -// MarshalJSON returns c as the JSON encoding of c. -func (c *Code) MarshalJSON() ([]byte, error) { - if c == nil { - return []byte("null"), nil - } - str, ok := codeToStr[*c] - if !ok { - return nil, fmt.Errorf("invalid code: %d", *c) - } - return []byte(fmt.Sprintf("%q", str)), nil -} diff --git a/vendor/go.opentelemetry.io/otel/codes/doc.go b/vendor/go.opentelemetry.io/otel/codes/doc.go deleted file mode 100644 index df3e0f1b62..0000000000 --- a/vendor/go.opentelemetry.io/otel/codes/doc.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package codes defines the canonical error codes used by OpenTelemetry. - -It conforms to [the OpenTelemetry -specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#statuscanonicalcode). -*/ -package codes // import "go.opentelemetry.io/otel/codes" diff --git a/vendor/go.opentelemetry.io/otel/internal/rawhelpers.go b/vendor/go.opentelemetry.io/otel/internal/rawhelpers.go deleted file mode 100644 index ce7afaa188..0000000000 --- a/vendor/go.opentelemetry.io/otel/internal/rawhelpers.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package internal // import "go.opentelemetry.io/otel/internal" - -import ( - "math" - "unsafe" -) - -func BoolToRaw(b bool) uint64 { - if b { - return 1 - } - return 0 -} - -func RawToBool(r uint64) bool { - return r != 0 -} - -func Int64ToRaw(i int64) uint64 { - return uint64(i) -} - -func RawToInt64(r uint64) int64 { - return int64(r) -} - -func Float64ToRaw(f float64) uint64 { - return math.Float64bits(f) -} - -func RawToFloat64(r uint64) float64 { - return math.Float64frombits(r) -} - -func RawPtrToFloat64Ptr(r *uint64) *float64 { - return (*float64)(unsafe.Pointer(r)) -} - -func RawPtrToInt64Ptr(r *uint64) *int64 { - return (*int64)(unsafe.Pointer(r)) -} diff --git a/vendor/go.opentelemetry.io/otel/trace/LICENSE b/vendor/go.opentelemetry.io/otel/trace/LICENSE deleted file mode 100644 index 261eeb9e9f..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/go.opentelemetry.io/otel/trace/config.go b/vendor/go.opentelemetry.io/otel/trace/config.go deleted file mode 100644 index f058cc781e..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/config.go +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import ( - "time" - - "go.opentelemetry.io/otel/attribute" -) - -// TracerConfig is a group of options for a Tracer. -type TracerConfig struct { - instrumentationVersion string - // Schema URL of the telemetry emitted by the Tracer. - schemaURL string -} - -// InstrumentationVersion returns the version of the library providing instrumentation. -func (t *TracerConfig) InstrumentationVersion() string { - return t.instrumentationVersion -} - -// SchemaURL returns the Schema URL of the telemetry emitted by the Tracer. -func (t *TracerConfig) SchemaURL() string { - return t.schemaURL -} - -// NewTracerConfig applies all the options to a returned TracerConfig. -func NewTracerConfig(options ...TracerOption) TracerConfig { - var config TracerConfig - for _, option := range options { - config = option.apply(config) - } - return config -} - -// TracerOption applies an option to a TracerConfig. -type TracerOption interface { - apply(TracerConfig) TracerConfig -} - -type tracerOptionFunc func(TracerConfig) TracerConfig - -func (fn tracerOptionFunc) apply(cfg TracerConfig) TracerConfig { - return fn(cfg) -} - -// SpanConfig is a group of options for a Span. -type SpanConfig struct { - attributes []attribute.KeyValue - timestamp time.Time - links []Link - newRoot bool - spanKind SpanKind - stackTrace bool -} - -// Attributes describe the associated qualities of a Span. -func (cfg *SpanConfig) Attributes() []attribute.KeyValue { - return cfg.attributes -} - -// Timestamp is a time in a Span life-cycle. -func (cfg *SpanConfig) Timestamp() time.Time { - return cfg.timestamp -} - -// StackTrace checks whether stack trace capturing is enabled. -func (cfg *SpanConfig) StackTrace() bool { - return cfg.stackTrace -} - -// Links are the associations a Span has with other Spans. -func (cfg *SpanConfig) Links() []Link { - return cfg.links -} - -// NewRoot identifies a Span as the root Span for a new trace. This is -// commonly used when an existing trace crosses trust boundaries and the -// remote parent span context should be ignored for security. -func (cfg *SpanConfig) NewRoot() bool { - return cfg.newRoot -} - -// SpanKind is the role a Span has in a trace. -func (cfg *SpanConfig) SpanKind() SpanKind { - return cfg.spanKind -} - -// NewSpanStartConfig applies all the options to a returned SpanConfig. -// No validation is performed on the returned SpanConfig (e.g. no uniqueness -// checking or bounding of data), it is left to the SDK to perform this -// action. -func NewSpanStartConfig(options ...SpanStartOption) SpanConfig { - var c SpanConfig - for _, option := range options { - c = option.applySpanStart(c) - } - return c -} - -// NewSpanEndConfig applies all the options to a returned SpanConfig. -// No validation is performed on the returned SpanConfig (e.g. no uniqueness -// checking or bounding of data), it is left to the SDK to perform this -// action. -func NewSpanEndConfig(options ...SpanEndOption) SpanConfig { - var c SpanConfig - for _, option := range options { - c = option.applySpanEnd(c) - } - return c -} - -// SpanStartOption applies an option to a SpanConfig. These options are applicable -// only when the span is created. -type SpanStartOption interface { - applySpanStart(SpanConfig) SpanConfig -} - -type spanOptionFunc func(SpanConfig) SpanConfig - -func (fn spanOptionFunc) applySpanStart(cfg SpanConfig) SpanConfig { - return fn(cfg) -} - -// SpanEndOption applies an option to a SpanConfig. These options are -// applicable only when the span is ended. -type SpanEndOption interface { - applySpanEnd(SpanConfig) SpanConfig -} - -// EventConfig is a group of options for an Event. -type EventConfig struct { - attributes []attribute.KeyValue - timestamp time.Time - stackTrace bool -} - -// Attributes describe the associated qualities of an Event. -func (cfg *EventConfig) Attributes() []attribute.KeyValue { - return cfg.attributes -} - -// Timestamp is a time in an Event life-cycle. -func (cfg *EventConfig) Timestamp() time.Time { - return cfg.timestamp -} - -// StackTrace checks whether stack trace capturing is enabled. -func (cfg *EventConfig) StackTrace() bool { - return cfg.stackTrace -} - -// NewEventConfig applies all the EventOptions to a returned EventConfig. If no -// timestamp option is passed, the returned EventConfig will have a Timestamp -// set to the call time, otherwise no validation is performed on the returned -// EventConfig. -func NewEventConfig(options ...EventOption) EventConfig { - var c EventConfig - for _, option := range options { - c = option.applyEvent(c) - } - if c.timestamp.IsZero() { - c.timestamp = time.Now() - } - return c -} - -// EventOption applies span event options to an EventConfig. -type EventOption interface { - applyEvent(EventConfig) EventConfig -} - -// SpanOption are options that can be used at both the beginning and end of a span. -type SpanOption interface { - SpanStartOption - SpanEndOption -} - -// SpanStartEventOption are options that can be used at the start of a span, or with an event. -type SpanStartEventOption interface { - SpanStartOption - EventOption -} - -// SpanEndEventOption are options that can be used at the end of a span, or with an event. -type SpanEndEventOption interface { - SpanEndOption - EventOption -} - -type attributeOption []attribute.KeyValue - -func (o attributeOption) applySpan(c SpanConfig) SpanConfig { - c.attributes = append(c.attributes, []attribute.KeyValue(o)...) - return c -} -func (o attributeOption) applySpanStart(c SpanConfig) SpanConfig { return o.applySpan(c) } -func (o attributeOption) applyEvent(c EventConfig) EventConfig { - c.attributes = append(c.attributes, []attribute.KeyValue(o)...) - return c -} - -var _ SpanStartEventOption = attributeOption{} - -// WithAttributes adds the attributes related to a span life-cycle event. -// These attributes are used to describe the work a Span represents when this -// option is provided to a Span's start or end events. Otherwise, these -// attributes provide additional information about the event being recorded -// (e.g. error, state change, processing progress, system event). -// -// If multiple of these options are passed the attributes of each successive -// option will extend the attributes instead of overwriting. There is no -// guarantee of uniqueness in the resulting attributes. -func WithAttributes(attributes ...attribute.KeyValue) SpanStartEventOption { - return attributeOption(attributes) -} - -// SpanEventOption are options that can be used with an event or a span. -type SpanEventOption interface { - SpanOption - EventOption -} - -type timestampOption time.Time - -func (o timestampOption) applySpan(c SpanConfig) SpanConfig { - c.timestamp = time.Time(o) - return c -} -func (o timestampOption) applySpanStart(c SpanConfig) SpanConfig { return o.applySpan(c) } -func (o timestampOption) applySpanEnd(c SpanConfig) SpanConfig { return o.applySpan(c) } -func (o timestampOption) applyEvent(c EventConfig) EventConfig { - c.timestamp = time.Time(o) - return c -} - -var _ SpanEventOption = timestampOption{} - -// WithTimestamp sets the time of a Span or Event life-cycle moment (e.g. -// started, stopped, errored). -func WithTimestamp(t time.Time) SpanEventOption { - return timestampOption(t) -} - -type stackTraceOption bool - -func (o stackTraceOption) applyEvent(c EventConfig) EventConfig { - c.stackTrace = bool(o) - return c -} -func (o stackTraceOption) applySpan(c SpanConfig) SpanConfig { - c.stackTrace = bool(o) - return c -} -func (o stackTraceOption) applySpanEnd(c SpanConfig) SpanConfig { return o.applySpan(c) } - -// WithStackTrace sets the flag to capture the error with stack trace (e.g. true, false). -func WithStackTrace(b bool) SpanEndEventOption { - return stackTraceOption(b) -} - -// WithLinks adds links to a Span. The links are added to the existing Span -// links, i.e. this does not overwrite. Links with invalid span context are ignored. -func WithLinks(links ...Link) SpanStartOption { - return spanOptionFunc(func(cfg SpanConfig) SpanConfig { - cfg.links = append(cfg.links, links...) - return cfg - }) -} - -// WithNewRoot specifies that the Span should be treated as a root Span. Any -// existing parent span context will be ignored when defining the Span's trace -// identifiers. -func WithNewRoot() SpanStartOption { - return spanOptionFunc(func(cfg SpanConfig) SpanConfig { - cfg.newRoot = true - return cfg - }) -} - -// WithSpanKind sets the SpanKind of a Span. -func WithSpanKind(kind SpanKind) SpanStartOption { - return spanOptionFunc(func(cfg SpanConfig) SpanConfig { - cfg.spanKind = kind - return cfg - }) -} - -// WithInstrumentationVersion sets the instrumentation version. -func WithInstrumentationVersion(version string) TracerOption { - return tracerOptionFunc(func(cfg TracerConfig) TracerConfig { - cfg.instrumentationVersion = version - return cfg - }) -} - -// WithSchemaURL sets the schema URL for the Tracer. -func WithSchemaURL(schemaURL string) TracerOption { - return tracerOptionFunc(func(cfg TracerConfig) TracerConfig { - cfg.schemaURL = schemaURL - return cfg - }) -} diff --git a/vendor/go.opentelemetry.io/otel/trace/context.go b/vendor/go.opentelemetry.io/otel/trace/context.go deleted file mode 100644 index 76f9a083c4..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/context.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import "context" - -type traceContextKeyType int - -const currentSpanKey traceContextKeyType = iota - -// ContextWithSpan returns a copy of parent with span set as the current Span. -func ContextWithSpan(parent context.Context, span Span) context.Context { - return context.WithValue(parent, currentSpanKey, span) -} - -// ContextWithSpanContext returns a copy of parent with sc as the current -// Span. The Span implementation that wraps sc is non-recording and performs -// no operations other than to return sc as the SpanContext from the -// SpanContext method. -func ContextWithSpanContext(parent context.Context, sc SpanContext) context.Context { - return ContextWithSpan(parent, nonRecordingSpan{sc: sc}) -} - -// ContextWithRemoteSpanContext returns a copy of parent with rsc set explicly -// as a remote SpanContext and as the current Span. The Span implementation -// that wraps rsc is non-recording and performs no operations other than to -// return rsc as the SpanContext from the SpanContext method. -func ContextWithRemoteSpanContext(parent context.Context, rsc SpanContext) context.Context { - return ContextWithSpanContext(parent, rsc.WithRemote(true)) -} - -// SpanFromContext returns the current Span from ctx. -// -// If no Span is currently set in ctx an implementation of a Span that -// performs no operations is returned. -func SpanFromContext(ctx context.Context) Span { - if ctx == nil { - return noopSpan{} - } - if span, ok := ctx.Value(currentSpanKey).(Span); ok { - return span - } - return noopSpan{} -} - -// SpanContextFromContext returns the current Span's SpanContext. -func SpanContextFromContext(ctx context.Context) SpanContext { - return SpanFromContext(ctx).SpanContext() -} diff --git a/vendor/go.opentelemetry.io/otel/trace/doc.go b/vendor/go.opentelemetry.io/otel/trace/doc.go deleted file mode 100644 index 391417718f..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/doc.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* -Package trace provides an implementation of the tracing part of the -OpenTelemetry API. - -To participate in distributed traces a Span needs to be created for the -operation being performed as part of a traced workflow. It its simplest form: - - var tracer trace.Tracer - - func init() { - tracer = otel.Tracer("instrumentation/package/name") - } - - func operation(ctx context.Context) { - var span trace.Span - ctx, span = tracer.Start(ctx, "operation") - defer span.End() - // ... - } - -A Tracer is unique to the instrumentation and is used to create Spans. -Instrumentation should be designed to accept a TracerProvider from which it -can create its own unique Tracer. Alternatively, the registered global -TracerProvider from the go.opentelemetry.io/otel package can be used as -a default. - - const ( - name = "instrumentation/package/name" - version = "0.1.0" - ) - - type Instrumentation struct { - tracer trace.Tracer - } - - func NewInstrumentation(tp trace.TracerProvider) *Instrumentation { - if tp == nil { - tp = otel.TracerProvider() - } - return &Instrumentation{ - tracer: tp.Tracer(name, trace.WithInstrumentationVersion(version)), - } - } - - func operation(ctx context.Context, inst *Instrumentation) { - var span trace.Span - ctx, span = inst.tracer.Start(ctx, "operation") - defer span.End() - // ... - } -*/ -package trace // import "go.opentelemetry.io/otel/trace" diff --git a/vendor/go.opentelemetry.io/otel/trace/nonrecording.go b/vendor/go.opentelemetry.io/otel/trace/nonrecording.go deleted file mode 100644 index 88fcb81611..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/nonrecording.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -// nonRecordingSpan is a minimal implementation of a Span that wraps a -// SpanContext. It performs no operations other than to return the wrapped -// SpanContext. -type nonRecordingSpan struct { - noopSpan - - sc SpanContext -} - -// SpanContext returns the wrapped SpanContext. -func (s nonRecordingSpan) SpanContext() SpanContext { return s.sc } diff --git a/vendor/go.opentelemetry.io/otel/trace/noop.go b/vendor/go.opentelemetry.io/otel/trace/noop.go deleted file mode 100644 index 73950f2077..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/noop.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" -) - -// NewNoopTracerProvider returns an implementation of TracerProvider that -// performs no operations. The Tracer and Spans created from the returned -// TracerProvider also perform no operations. -func NewNoopTracerProvider() TracerProvider { - return noopTracerProvider{} -} - -type noopTracerProvider struct{} - -var _ TracerProvider = noopTracerProvider{} - -// Tracer returns noop implementation of Tracer. -func (p noopTracerProvider) Tracer(string, ...TracerOption) Tracer { - return noopTracer{} -} - -// noopTracer is an implementation of Tracer that preforms no operations. -type noopTracer struct{} - -var _ Tracer = noopTracer{} - -// Start carries forward a non-recording Span, if one is present in the context, otherwise it -// creates a no-op Span. -func (t noopTracer) Start(ctx context.Context, name string, _ ...SpanStartOption) (context.Context, Span) { - span := SpanFromContext(ctx) - if _, ok := span.(nonRecordingSpan); !ok { - // span is likely already a noopSpan, but let's be sure - span = noopSpan{} - } - return ContextWithSpan(ctx, span), span -} - -// noopSpan is an implementation of Span that preforms no operations. -type noopSpan struct{} - -var _ Span = noopSpan{} - -// SpanContext returns an empty span context. -func (noopSpan) SpanContext() SpanContext { return SpanContext{} } - -// IsRecording always returns false. -func (noopSpan) IsRecording() bool { return false } - -// SetStatus does nothing. -func (noopSpan) SetStatus(codes.Code, string) {} - -// SetError does nothing. -func (noopSpan) SetError(bool) {} - -// SetAttributes does nothing. -func (noopSpan) SetAttributes(...attribute.KeyValue) {} - -// End does nothing. -func (noopSpan) End(...SpanEndOption) {} - -// RecordError does nothing. -func (noopSpan) RecordError(error, ...EventOption) {} - -// AddEvent does nothing. -func (noopSpan) AddEvent(string, ...EventOption) {} - -// SetName does nothing. -func (noopSpan) SetName(string) {} - -// TracerProvider returns a no-op TracerProvider. -func (noopSpan) TracerProvider() TracerProvider { return noopTracerProvider{} } diff --git a/vendor/go.opentelemetry.io/otel/trace/trace.go b/vendor/go.opentelemetry.io/otel/trace/trace.go deleted file mode 100644 index 1bc040c276..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/trace.go +++ /dev/null @@ -1,519 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import ( - "bytes" - "context" - "encoding/hex" - "encoding/json" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" -) - -const ( - // FlagsSampled is a bitmask with the sampled bit set. A SpanContext - // with the sampling bit set means the span is sampled. - FlagsSampled = TraceFlags(0x01) - - errInvalidHexID errorConst = "trace-id and span-id can only contain [0-9a-f] characters, all lowercase" - - errInvalidTraceIDLength errorConst = "hex encoded trace-id must have length equals to 32" - errNilTraceID errorConst = "trace-id can't be all zero" - - errInvalidSpanIDLength errorConst = "hex encoded span-id must have length equals to 16" - errNilSpanID errorConst = "span-id can't be all zero" -) - -type errorConst string - -func (e errorConst) Error() string { - return string(e) -} - -// TraceID is a unique identity of a trace. -// nolint:revive // revive complains about stutter of `trace.TraceID`. -type TraceID [16]byte - -var nilTraceID TraceID -var _ json.Marshaler = nilTraceID - -// IsValid checks whether the trace TraceID is valid. A valid trace ID does -// not consist of zeros only. -func (t TraceID) IsValid() bool { - return !bytes.Equal(t[:], nilTraceID[:]) -} - -// MarshalJSON implements a custom marshal function to encode TraceID -// as a hex string. -func (t TraceID) MarshalJSON() ([]byte, error) { - return json.Marshal(t.String()) -} - -// String returns the hex string representation form of a TraceID. -func (t TraceID) String() string { - return hex.EncodeToString(t[:]) -} - -// SpanID is a unique identity of a span in a trace. -type SpanID [8]byte - -var nilSpanID SpanID -var _ json.Marshaler = nilSpanID - -// IsValid checks whether the SpanID is valid. A valid SpanID does not consist -// of zeros only. -func (s SpanID) IsValid() bool { - return !bytes.Equal(s[:], nilSpanID[:]) -} - -// MarshalJSON implements a custom marshal function to encode SpanID -// as a hex string. -func (s SpanID) MarshalJSON() ([]byte, error) { - return json.Marshal(s.String()) -} - -// String returns the hex string representation form of a SpanID. -func (s SpanID) String() string { - return hex.EncodeToString(s[:]) -} - -// TraceIDFromHex returns a TraceID from a hex string if it is compliant with -// the W3C trace-context specification. See more at -// https://www.w3.org/TR/trace-context/#trace-id -// nolint:revive // revive complains about stutter of `trace.TraceIDFromHex`. -func TraceIDFromHex(h string) (TraceID, error) { - t := TraceID{} - if len(h) != 32 { - return t, errInvalidTraceIDLength - } - - if err := decodeHex(h, t[:]); err != nil { - return t, err - } - - if !t.IsValid() { - return t, errNilTraceID - } - return t, nil -} - -// SpanIDFromHex returns a SpanID from a hex string if it is compliant -// with the w3c trace-context specification. -// See more at https://www.w3.org/TR/trace-context/#parent-id -func SpanIDFromHex(h string) (SpanID, error) { - s := SpanID{} - if len(h) != 16 { - return s, errInvalidSpanIDLength - } - - if err := decodeHex(h, s[:]); err != nil { - return s, err - } - - if !s.IsValid() { - return s, errNilSpanID - } - return s, nil -} - -func decodeHex(h string, b []byte) error { - for _, r := range h { - switch { - case 'a' <= r && r <= 'f': - continue - case '0' <= r && r <= '9': - continue - default: - return errInvalidHexID - } - } - - decoded, err := hex.DecodeString(h) - if err != nil { - return err - } - - copy(b, decoded) - return nil -} - -// TraceFlags contains flags that can be set on a SpanContext. -type TraceFlags byte //nolint:revive // revive complains about stutter of `trace.TraceFlags`. - -// IsSampled returns if the sampling bit is set in the TraceFlags. -func (tf TraceFlags) IsSampled() bool { - return tf&FlagsSampled == FlagsSampled -} - -// WithSampled sets the sampling bit in a new copy of the TraceFlags. -func (tf TraceFlags) WithSampled(sampled bool) TraceFlags { - if sampled { - return tf | FlagsSampled - } - - return tf &^ FlagsSampled -} - -// MarshalJSON implements a custom marshal function to encode TraceFlags -// as a hex string. -func (tf TraceFlags) MarshalJSON() ([]byte, error) { - return json.Marshal(tf.String()) -} - -// String returns the hex string representation form of TraceFlags. -func (tf TraceFlags) String() string { - return hex.EncodeToString([]byte{byte(tf)}[:]) -} - -// SpanContextConfig contains mutable fields usable for constructing -// an immutable SpanContext. -type SpanContextConfig struct { - TraceID TraceID - SpanID SpanID - TraceFlags TraceFlags - TraceState TraceState - Remote bool -} - -// NewSpanContext constructs a SpanContext using values from the provided -// SpanContextConfig. -func NewSpanContext(config SpanContextConfig) SpanContext { - return SpanContext{ - traceID: config.TraceID, - spanID: config.SpanID, - traceFlags: config.TraceFlags, - traceState: config.TraceState, - remote: config.Remote, - } -} - -// SpanContext contains identifying trace information about a Span. -type SpanContext struct { - traceID TraceID - spanID SpanID - traceFlags TraceFlags - traceState TraceState - remote bool -} - -var _ json.Marshaler = SpanContext{} - -// IsValid returns if the SpanContext is valid. A valid span context has a -// valid TraceID and SpanID. -func (sc SpanContext) IsValid() bool { - return sc.HasTraceID() && sc.HasSpanID() -} - -// IsRemote indicates whether the SpanContext represents a remotely-created Span. -func (sc SpanContext) IsRemote() bool { - return sc.remote -} - -// WithRemote returns a copy of sc with the Remote property set to remote. -func (sc SpanContext) WithRemote(remote bool) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: sc.spanID, - traceFlags: sc.traceFlags, - traceState: sc.traceState, - remote: remote, - } -} - -// TraceID returns the TraceID from the SpanContext. -func (sc SpanContext) TraceID() TraceID { - return sc.traceID -} - -// HasTraceID checks if the SpanContext has a valid TraceID. -func (sc SpanContext) HasTraceID() bool { - return sc.traceID.IsValid() -} - -// WithTraceID returns a new SpanContext with the TraceID replaced. -func (sc SpanContext) WithTraceID(traceID TraceID) SpanContext { - return SpanContext{ - traceID: traceID, - spanID: sc.spanID, - traceFlags: sc.traceFlags, - traceState: sc.traceState, - remote: sc.remote, - } -} - -// SpanID returns the SpanID from the SpanContext. -func (sc SpanContext) SpanID() SpanID { - return sc.spanID -} - -// HasSpanID checks if the SpanContext has a valid SpanID. -func (sc SpanContext) HasSpanID() bool { - return sc.spanID.IsValid() -} - -// WithSpanID returns a new SpanContext with the SpanID replaced. -func (sc SpanContext) WithSpanID(spanID SpanID) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: spanID, - traceFlags: sc.traceFlags, - traceState: sc.traceState, - remote: sc.remote, - } -} - -// TraceFlags returns the flags from the SpanContext. -func (sc SpanContext) TraceFlags() TraceFlags { - return sc.traceFlags -} - -// IsSampled returns if the sampling bit is set in the SpanContext's TraceFlags. -func (sc SpanContext) IsSampled() bool { - return sc.traceFlags.IsSampled() -} - -// WithTraceFlags returns a new SpanContext with the TraceFlags replaced. -func (sc SpanContext) WithTraceFlags(flags TraceFlags) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: sc.spanID, - traceFlags: flags, - traceState: sc.traceState, - remote: sc.remote, - } -} - -// TraceState returns the TraceState from the SpanContext. -func (sc SpanContext) TraceState() TraceState { - return sc.traceState -} - -// WithTraceState returns a new SpanContext with the TraceState replaced. -func (sc SpanContext) WithTraceState(state TraceState) SpanContext { - return SpanContext{ - traceID: sc.traceID, - spanID: sc.spanID, - traceFlags: sc.traceFlags, - traceState: state, - remote: sc.remote, - } -} - -// Equal is a predicate that determines whether two SpanContext values are equal. -func (sc SpanContext) Equal(other SpanContext) bool { - return sc.traceID == other.traceID && - sc.spanID == other.spanID && - sc.traceFlags == other.traceFlags && - sc.traceState.String() == other.traceState.String() && - sc.remote == other.remote -} - -// MarshalJSON implements a custom marshal function to encode a SpanContext. -func (sc SpanContext) MarshalJSON() ([]byte, error) { - return json.Marshal(SpanContextConfig{ - TraceID: sc.traceID, - SpanID: sc.spanID, - TraceFlags: sc.traceFlags, - TraceState: sc.traceState, - Remote: sc.remote, - }) -} - -// Span is the individual component of a trace. It represents a single named -// and timed operation of a workflow that is traced. A Tracer is used to -// create a Span and it is then up to the operation the Span represents to -// properly end the Span when the operation itself ends. -// -// Warning: methods may be added to this interface in minor releases. -type Span interface { - // End completes the Span. The Span is considered complete and ready to be - // delivered through the rest of the telemetry pipeline after this method - // is called. Therefore, updates to the Span are not allowed after this - // method has been called. - End(options ...SpanEndOption) - - // AddEvent adds an event with the provided name and options. - AddEvent(name string, options ...EventOption) - - // IsRecording returns the recording state of the Span. It will return - // true if the Span is active and events can be recorded. - IsRecording() bool - - // RecordError will record err as an exception span event for this span. An - // additional call to SetStatus is required if the Status of the Span should - // be set to Error, as this method does not change the Span status. If this - // span is not being recorded or err is nil then this method does nothing. - RecordError(err error, options ...EventOption) - - // SpanContext returns the SpanContext of the Span. The returned SpanContext - // is usable even after the End method has been called for the Span. - SpanContext() SpanContext - - // SetStatus sets the status of the Span in the form of a code and a - // description, overriding previous values set. The description is only - // included in a status when the code is for an error. - SetStatus(code codes.Code, description string) - - // SetName sets the Span name. - SetName(name string) - - // SetAttributes sets kv as attributes of the Span. If a key from kv - // already exists for an attribute of the Span it will be overwritten with - // the value contained in kv. - SetAttributes(kv ...attribute.KeyValue) - - // TracerProvider returns a TracerProvider that can be used to generate - // additional Spans on the same telemetry pipeline as the current Span. - TracerProvider() TracerProvider -} - -// Link is the relationship between two Spans. The relationship can be within -// the same Trace or across different Traces. -// -// For example, a Link is used in the following situations: -// -// 1. Batch Processing: A batch of operations may contain operations -// associated with one or more traces/spans. Since there can only be one -// parent SpanContext, a Link is used to keep reference to the -// SpanContext of all operations in the batch. -// 2. Public Endpoint: A SpanContext for an in incoming client request on a -// public endpoint should be considered untrusted. In such a case, a new -// trace with its own identity and sampling decision needs to be created, -// but this new trace needs to be related to the original trace in some -// form. A Link is used to keep reference to the original SpanContext and -// track the relationship. -type Link struct { - // SpanContext of the linked Span. - SpanContext SpanContext - - // Attributes describe the aspects of the link. - Attributes []attribute.KeyValue -} - -// LinkFromContext returns a link encapsulating the SpanContext in the provided ctx. -func LinkFromContext(ctx context.Context, attrs ...attribute.KeyValue) Link { - return Link{ - SpanContext: SpanContextFromContext(ctx), - Attributes: attrs, - } -} - -// SpanKind is the role a Span plays in a Trace. -type SpanKind int - -// As a convenience, these match the proto definition, see -// https://github.com/open-telemetry/opentelemetry-proto/blob/30d237e1ff3ab7aa50e0922b5bebdd93505090af/opentelemetry/proto/trace/v1/trace.proto#L101-L129 -// -// The unspecified value is not a valid `SpanKind`. Use `ValidateSpanKind()` -// to coerce a span kind to a valid value. -const ( - // SpanKindUnspecified is an unspecified SpanKind and is not a valid - // SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal - // if it is received. - SpanKindUnspecified SpanKind = 0 - // SpanKindInternal is a SpanKind for a Span that represents an internal - // operation within an application. - SpanKindInternal SpanKind = 1 - // SpanKindServer is a SpanKind for a Span that represents the operation - // of handling a request from a client. - SpanKindServer SpanKind = 2 - // SpanKindClient is a SpanKind for a Span that represents the operation - // of client making a request to a server. - SpanKindClient SpanKind = 3 - // SpanKindProducer is a SpanKind for a Span that represents the operation - // of a producer sending a message to a message broker. Unlike - // SpanKindClient and SpanKindServer, there is often no direct - // relationship between this kind of Span and a SpanKindConsumer kind. A - // SpanKindProducer Span will end once the message is accepted by the - // message broker which might not overlap with the processing of that - // message. - SpanKindProducer SpanKind = 4 - // SpanKindConsumer is a SpanKind for a Span that represents the operation - // of a consumer receiving a message from a message broker. Like - // SpanKindProducer Spans, there is often no direct relationship between - // this Span and the Span that produced the message. - SpanKindConsumer SpanKind = 5 -) - -// ValidateSpanKind returns a valid span kind value. This will coerce -// invalid values into the default value, SpanKindInternal. -func ValidateSpanKind(spanKind SpanKind) SpanKind { - switch spanKind { - case SpanKindInternal, - SpanKindServer, - SpanKindClient, - SpanKindProducer, - SpanKindConsumer: - // valid - return spanKind - default: - return SpanKindInternal - } -} - -// String returns the specified name of the SpanKind in lower-case. -func (sk SpanKind) String() string { - switch sk { - case SpanKindInternal: - return "internal" - case SpanKindServer: - return "server" - case SpanKindClient: - return "client" - case SpanKindProducer: - return "producer" - case SpanKindConsumer: - return "consumer" - default: - return "unspecified" - } -} - -// Tracer is the creator of Spans. -// -// Warning: methods may be added to this interface in minor releases. -type Tracer interface { - // Start creates a span and a context.Context containing the newly-created span. - // - // If the context.Context provided in `ctx` contains a Span then the newly-created - // Span will be a child of that span, otherwise it will be a root span. This behavior - // can be overridden by providing `WithNewRoot()` as a SpanOption, causing the - // newly-created Span to be a root span even if `ctx` contains a Span. - // - // When creating a Span it is recommended to provide all known span attributes using - // the `WithAttributes()` SpanOption as samplers will only have access to the - // attributes provided when a Span is created. - // - // Any Span that is created MUST also be ended. This is the responsibility of the user. - // Implementations of this API may leak memory or other resources if Spans are not ended. - Start(ctx context.Context, spanName string, opts ...SpanStartOption) (context.Context, Span) -} - -// TracerProvider provides access to instrumentation Tracers. -// -// Warning: methods may be added to this interface in minor releases. -type TracerProvider interface { - // Tracer creates an implementation of the Tracer interface. - // The instrumentationName must be the name of the library providing - // instrumentation. This name may be the same as the instrumented code - // only if that code provides built-in instrumentation. If the - // instrumentationName is empty, then a implementation defined default - // name will be used instead. - // - // This method must be concurrency safe. - Tracer(instrumentationName string, opts ...TracerOption) Tracer -} diff --git a/vendor/go.opentelemetry.io/otel/trace/tracestate.go b/vendor/go.opentelemetry.io/otel/trace/tracestate.go deleted file mode 100644 index 7b7af6955f..0000000000 --- a/vendor/go.opentelemetry.io/otel/trace/tracestate.go +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package trace // import "go.opentelemetry.io/otel/trace" - -import ( - "encoding/json" - "fmt" - "regexp" - "strings" -) - -var ( - maxListMembers = 32 - - listDelimiter = "," - - // based on the W3C Trace Context specification, see - // https://www.w3.org/TR/trace-context-1/#tracestate-header - noTenantKeyFormat = `[a-z][_0-9a-z\-\*\/]{0,255}` - withTenantKeyFormat = `[a-z0-9][_0-9a-z\-\*\/]{0,240}@[a-z][_0-9a-z\-\*\/]{0,13}` - valueFormat = `[\x20-\x2b\x2d-\x3c\x3e-\x7e]{0,255}[\x21-\x2b\x2d-\x3c\x3e-\x7e]` - - keyRe = regexp.MustCompile(`^((` + noTenantKeyFormat + `)|(` + withTenantKeyFormat + `))$`) - valueRe = regexp.MustCompile(`^(` + valueFormat + `)$`) - memberRe = regexp.MustCompile(`^\s*((` + noTenantKeyFormat + `)|(` + withTenantKeyFormat + `))=(` + valueFormat + `)\s*$`) - - errInvalidKey errorConst = "invalid tracestate key" - errInvalidValue errorConst = "invalid tracestate value" - errInvalidMember errorConst = "invalid tracestate list-member" - errMemberNumber errorConst = "too many list-members in tracestate" - errDuplicate errorConst = "duplicate list-member in tracestate" -) - -type member struct { - Key string - Value string -} - -func newMember(key, value string) (member, error) { - if !keyRe.MatchString(key) { - return member{}, fmt.Errorf("%w: %s", errInvalidKey, key) - } - if !valueRe.MatchString(value) { - return member{}, fmt.Errorf("%w: %s", errInvalidValue, value) - } - return member{Key: key, Value: value}, nil -} - -func parseMember(m string) (member, error) { - matches := memberRe.FindStringSubmatch(m) - if len(matches) != 5 { - return member{}, fmt.Errorf("%w: %s", errInvalidMember, m) - } - - return member{ - Key: matches[1], - Value: matches[4], - }, nil - -} - -// String encodes member into a string compliant with the W3C Trace Context -// specification. -func (m member) String() string { - return fmt.Sprintf("%s=%s", m.Key, m.Value) -} - -// TraceState provides additional vendor-specific trace identification -// information across different distributed tracing systems. It represents an -// immutable list consisting of key/value pairs, each pair is referred to as a -// list-member. -// -// TraceState conforms to the W3C Trace Context specification -// (https://www.w3.org/TR/trace-context-1). All operations that create or copy -// a TraceState do so by validating all input and will only produce TraceState -// that conform to the specification. Specifically, this means that all -// list-member's key/value pairs are valid, no duplicate list-members exist, -// and the maximum number of list-members (32) is not exceeded. -type TraceState struct { //nolint:revive // revive complains about stutter of `trace.TraceState` - // list is the members in order. - list []member -} - -var _ json.Marshaler = TraceState{} - -// ParseTraceState attempts to decode a TraceState from the passed -// string. It returns an error if the input is invalid according to the W3C -// Trace Context specification. -func ParseTraceState(tracestate string) (TraceState, error) { - if tracestate == "" { - return TraceState{}, nil - } - - wrapErr := func(err error) error { - return fmt.Errorf("failed to parse tracestate: %w", err) - } - - var members []member - found := make(map[string]struct{}) - for _, memberStr := range strings.Split(tracestate, listDelimiter) { - if len(memberStr) == 0 { - continue - } - - m, err := parseMember(memberStr) - if err != nil { - return TraceState{}, wrapErr(err) - } - - if _, ok := found[m.Key]; ok { - return TraceState{}, wrapErr(errDuplicate) - } - found[m.Key] = struct{}{} - - members = append(members, m) - if n := len(members); n > maxListMembers { - return TraceState{}, wrapErr(errMemberNumber) - } - } - - return TraceState{list: members}, nil -} - -// MarshalJSON marshals the TraceState into JSON. -func (ts TraceState) MarshalJSON() ([]byte, error) { - return json.Marshal(ts.String()) -} - -// String encodes the TraceState into a string compliant with the W3C -// Trace Context specification. The returned string will be invalid if the -// TraceState contains any invalid members. -func (ts TraceState) String() string { - members := make([]string, len(ts.list)) - for i, m := range ts.list { - members[i] = m.String() - } - return strings.Join(members, listDelimiter) -} - -// Get returns the value paired with key from the corresponding TraceState -// list-member if it exists, otherwise an empty string is returned. -func (ts TraceState) Get(key string) string { - for _, member := range ts.list { - if member.Key == key { - return member.Value - } - } - - return "" -} - -// Insert adds a new list-member defined by the key/value pair to the -// TraceState. If a list-member already exists for the given key, that -// list-member's value is updated. The new or updated list-member is always -// moved to the beginning of the TraceState as specified by the W3C Trace -// Context specification. -// -// If key or value are invalid according to the W3C Trace Context -// specification an error is returned with the original TraceState. -// -// If adding a new list-member means the TraceState would have more members -// then is allowed, the new list-member will be inserted and the right-most -// list-member will be dropped in the returned TraceState. -func (ts TraceState) Insert(key, value string) (TraceState, error) { - m, err := newMember(key, value) - if err != nil { - return ts, err - } - - cTS := ts.Delete(key) - if cTS.Len()+1 <= maxListMembers { - cTS.list = append(cTS.list, member{}) - } - // When the number of members exceeds capacity, drop the "right-most". - copy(cTS.list[1:], cTS.list) - cTS.list[0] = m - - return cTS, nil -} - -// Delete returns a copy of the TraceState with the list-member identified by -// key removed. -func (ts TraceState) Delete(key string) TraceState { - members := make([]member, ts.Len()) - copy(members, ts.list) - for i, member := range ts.list { - if member.Key == key { - members = append(members[:i], members[i+1:]...) - // TraceState should contain no duplicate members. - break - } - } - return TraceState{list: members} -} - -// Len returns the number of list-members in the TraceState. -func (ts TraceState) Len() int { - return len(ts.list) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0cfe7ca50b..d346e7a94f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -46,19 +46,16 @@ github.com/Azure/go-autorest/logger # github.com/Azure/go-autorest/tracing v0.5.0 ## explicit; go 1.12 github.com/Azure/go-autorest/tracing -# github.com/ClickHouse/clickhouse-go/v2 v2.1.0 -## explicit; go 1.16 -github.com/ClickHouse/clickhouse-go/v2 -github.com/ClickHouse/clickhouse-go/v2/contributors -github.com/ClickHouse/clickhouse-go/v2/ext -github.com/ClickHouse/clickhouse-go/v2/lib/binary -github.com/ClickHouse/clickhouse-go/v2/lib/cityhash102 -github.com/ClickHouse/clickhouse-go/v2/lib/column -github.com/ClickHouse/clickhouse-go/v2/lib/compress -github.com/ClickHouse/clickhouse-go/v2/lib/driver -github.com/ClickHouse/clickhouse-go/v2/lib/io -github.com/ClickHouse/clickhouse-go/v2/lib/proto -github.com/ClickHouse/clickhouse-go/v2/lib/timezone +# github.com/ClickHouse/clickhouse-go v1.5.4 +## explicit; go 1.12 +github.com/ClickHouse/clickhouse-go +github.com/ClickHouse/clickhouse-go/lib/binary +github.com/ClickHouse/clickhouse-go/lib/cityhash102 +github.com/ClickHouse/clickhouse-go/lib/column +github.com/ClickHouse/clickhouse-go/lib/data +github.com/ClickHouse/clickhouse-go/lib/lz4 +github.com/ClickHouse/clickhouse-go/lib/protocol +github.com/ClickHouse/clickhouse-go/lib/types # github.com/DataDog/dd-trace-go v0.6.1 ## explicit github.com/DataDog/dd-trace-go/opentracing @@ -288,6 +285,9 @@ github.com/cespare/xxhash/v2 ## explicit; go 1.12 github.com/cheggaaa/pb/v3 github.com/cheggaaa/pb/v3/termutil +# github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58 +## explicit +github.com/cloudflare/golz4 # github.com/coredns/coredns v1.3.0 ## explicit github.com/coredns/coredns/core/dnsserver @@ -486,6 +486,8 @@ github.com/golang/snappy # github.com/google/btree v1.0.0 ## explicit github.com/google/btree +# github.com/google/go-cmp v0.5.7 +## explicit; go 1.11 # github.com/google/go-querystring v1.0.0 ## explicit github.com/google/go-querystring/query @@ -748,9 +750,6 @@ github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/scribe github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/zipkincore github.com/openzipkin/zipkin-go-opentracing/types github.com/openzipkin/zipkin-go-opentracing/wire -# github.com/paulmach/orb v0.7.1 -## explicit; go 1.15 -github.com/paulmach/orb # github.com/philhofer/fwd v1.0.0 ## explicit github.com/philhofer/fwd @@ -826,9 +825,6 @@ github.com/shirou/gopsutil/internal/common github.com/shirou/gopsutil/mem github.com/shirou/gopsutil/net github.com/shirou/gopsutil/process -# github.com/shopspring/decimal v1.3.1 -## explicit; go 1.13 -github.com/shopspring/decimal # github.com/sirupsen/logrus v1.6.0 ## explicit; go 1.13 github.com/sirupsen/logrus @@ -976,14 +972,6 @@ go.opencensus.io/trace go.opencensus.io/trace/internal go.opencensus.io/trace/propagation go.opencensus.io/trace/tracestate -# go.opentelemetry.io/otel v1.7.0 -## explicit; go 1.16 -go.opentelemetry.io/otel/attribute -go.opentelemetry.io/otel/codes -go.opentelemetry.io/otel/internal -# go.opentelemetry.io/otel/trace v1.7.0 -## explicit; go 1.16 -go.opentelemetry.io/otel/trace # go.uber.org/atomic v1.7.0 ## explicit; go 1.13 go.uber.org/atomic @@ -1495,7 +1483,7 @@ yunion.io/x/pkg/utils # yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e ## explicit; go 1.12 yunion.io/x/s3cli -# yunion.io/x/sqlchemy v1.1.2-0.20220701050442-4a04411dc606 +# yunion.io/x/sqlchemy v1.1.2-0.20220701113246-498f1b8c1941 ## explicit; go 1.17 yunion.io/x/sqlchemy yunion.io/x/sqlchemy/backends diff --git a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go index 23690463de..bf3a76bb85 100644 --- a/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go +++ b/vendor/yunion.io/x/sqlchemy/backends/clickhouse/clickhouse.go @@ -19,7 +19,7 @@ import ( "reflect" "strings" - _ "github.com/ClickHouse/clickhouse-go/v2" + _ "github.com/ClickHouse/clickhouse-go" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/gotypes"