Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: rename ceresdb to horaedb #48

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 The HoraeDB 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.

name: CI

on:
Expand Down
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 The HoraeDB 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.

run:
deadline: 5m
skip-files:
Expand Down
18 changes: 0 additions & 18 deletions CHANGELOG.md

This file was deleted.

3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

default: build

GO_TOOLS_BIN_PATH := $(shell pwd)/.tools/bin
Expand All @@ -20,7 +19,7 @@ lint:
revive -formatter friendly -config revive.toml ./...

check-license:
sh ./tools/check-license.sh
docker run --rm -v $(shell pwd):/github/workspace ghcr.io/korandoru/hawkeye-native:v3 check

test:
go test -timeout 5m -race -cover ./...
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ Golang client for [HoraeDB](https://github.com/CeresDB/horaedb).
Please refer [Golang SDK docs](https://ceresdb.github.io/docs/en/sdk/go.html).

## License
Under [Apache License 2.0](./LICENSE).

## Community and support
- Join the user group on [Slack](https://join.slack.com/t/ceresdbcommunity/shared_invite/zt-1au1ihbdy-5huC9J9s2462yBMIWmerTw)
- Join the user group on WeChat [WeChat QR code](https://github.com/CeresDB/community/blob/main/communication/wechat/group_qrcode.png)
- Join the user group on DingTalk: 44602802
Under [Apache License 2.0](LICENSE).
27 changes: 0 additions & 27 deletions ceresdb/client.go

This file was deleted.

54 changes: 34 additions & 20 deletions examples/read_write.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.
/*
* Copyright 2022 The HoraeDB 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 main

Expand All @@ -8,19 +22,19 @@ import (
"os"
"time"

"github.com/CeresDB/ceresdb-client-go/ceresdb"
"github.com/CeresDB/horaedb-client-go/horaedb"
)

var endpoint = "127.0.0.1:8831"

func init() {
if v := os.Getenv("CERESDB_ADDR"); v != "" {
if v := os.Getenv("HORAEDB_ADDR"); v != "" {
endpoint = v
}
}

func existsTable(client ceresdb.Client) error {
req := ceresdb.SQLQueryRequest{
func existsTable(client horaedb.Client) error {
req := horaedb.SQLQueryRequest{
Tables: []string{"demo"},
SQL: "EXISTS TABLE demo",
}
Expand All @@ -33,14 +47,14 @@ func existsTable(client ceresdb.Client) error {
return nil
}

func createTable(client ceresdb.Client) error {
func createTable(client horaedb.Client) error {
createTableSQL := `CREATE TABLE IF NOT EXISTS demo (
name string TAG,
value double,
t timestamp NOT NULL,
TIMESTAMP KEY(t)) ENGINE=Analytic with (enable_ttl=false)`

req := ceresdb.SQLQueryRequest{
req := horaedb.SQLQueryRequest{
Tables: []string{"demo"},
SQL: createTableSQL,
}
Expand All @@ -53,9 +67,9 @@ func createTable(client ceresdb.Client) error {
return nil
}

func dropTable(client ceresdb.Client) error {
func dropTable(client horaedb.Client) error {
dropTableSQL := `DROP TABLE demo`
req := ceresdb.SQLQueryRequest{
req := horaedb.SQLQueryRequest{
Tables: []string{"demo"},
SQL: dropTableSQL,
}
Expand All @@ -68,21 +82,21 @@ func dropTable(client ceresdb.Client) error {
return nil
}

func writeTable(client ceresdb.Client) error {
func writeTable(client horaedb.Client) error {
nowInMs := time.Now().UnixNano() / int64(time.Millisecond)
points := make([]ceresdb.Point, 0, 2)
points := make([]horaedb.Point, 0, 2)
for i := 0; i < 2; i++ {
point, err := ceresdb.NewPointBuilder("demo").
point, err := horaedb.NewPointBuilder("demo").
SetTimestamp(nowInMs).
AddTag("name", ceresdb.NewStringValue("test_tag1")).
AddField("value", ceresdb.NewDoubleValue(0.4242)).
AddTag("name", horaedb.NewStringValue("test_tag1")).
AddField("value", horaedb.NewDoubleValue(0.4242)).
Build()
if err != nil {
return err
}
points = append(points, point)
}
req := ceresdb.WriteRequest{
req := horaedb.WriteRequest{
Points: points,
}
resp, err := client.Write(context.Background(), req)
Expand All @@ -98,9 +112,9 @@ func writeTable(client ceresdb.Client) error {
return nil
}

func queryTable(client ceresdb.Client) error {
func queryTable(client horaedb.Client) error {
querySQL := `SELECT * FROM demo`
req := ceresdb.SQLQueryRequest{
req := horaedb.SQLQueryRequest{
Tables: []string{"demo"},
SQL: querySQL,
}
Expand All @@ -116,9 +130,9 @@ func queryTable(client ceresdb.Client) error {
func main() {
fmt.Println("------------------------------------------------------------------")
fmt.Println("### new client:")
client, err := ceresdb.NewClient(endpoint, ceresdb.Direct,
ceresdb.WithDefaultDatabase("public"),
ceresdb.EnableLoggerDebug(true),
client, err := horaedb.NewClient(endpoint, horaedb.Direct,
horaedb.WithDefaultDatabase("public"),
horaedb.EnableLoggerDebug(true),
)
if err != nil {
fmt.Printf("new ceresdb client fail, err: %v\n", err)
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/CeresDB/ceresdb-client-go
module github.com/CeresDB/horaedb-client-go

go 1.17

require (
github.com/CeresDB/ceresdbproto/golang v0.0.0-20230228090856-37ba6214b131
github.com/CeresDB/horaedbproto/golang v0.0.0-20231129131648-5d5d868218c3
github.com/apache/arrow/go/arrow v0.0.0-20211112161151-bc219186db40
github.com/hashicorp/golang-lru v1.0.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.1
google.golang.org/grpc v1.47.0
)
Expand All @@ -20,8 +21,6 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
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/CeresDB/ceresdbproto/golang v0.0.0-20230228090856-37ba6214b131 h1:ePzWeIoLOT4FsdjNrmEVrrtm412H2xHM6ZNLamB0bqk=
github.com/CeresDB/ceresdbproto/golang v0.0.0-20230228090856-37ba6214b131/go.mod h1:qLTh6jtSu2ZLIFsU3iiDIKvkrQvyY/Csg6Mk0Ub0QZ4=
github.com/CeresDB/horaedbproto/golang v0.0.0-20231129131648-5d5d868218c3 h1:RgOKVfdbnF4W5/TVFf7cIahom5HcV1v0GP2BYDc0BEM=
github.com/CeresDB/horaedbproto/golang v0.0.0-20231129131648-5d5d868218c3/go.mod h1:RHgzmQBZC4P5+Jm58flXMynMFGbiVQrw1t2ce3wLVas=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/arrow/go/arrow v0.0.0-20211112161151-bc219186db40 h1:q4dksr6ICHXqG5hm0ZW5IHyeEJXoIJSOZeBLmWPNeIQ=
Expand Down Expand Up @@ -67,9 +67,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
Expand Down
41 changes: 41 additions & 0 deletions horaedb/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2022 The HoraeDB 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 horaedb

import (
"context"
)

type RouteMode int

const (
Direct RouteMode = iota
Proxy
)

type Client interface {
Write(context.Context, WriteRequest) (WriteResponse, error)
SQLQuery(context.Context, SQLQueryRequest) (SQLQueryResponse, error)
}

func NewClient(endpoint string, routeMode RouteMode, opts ...Option) (Client, error) {
defaultOpts := defaultOptions()
for _, opt := range opts {
opt.apply(defaultOpts)
}
return newClient(endpoint, routeMode, *defaultOpts)
}
22 changes: 18 additions & 4 deletions ceresdb/client_impl.go → horaedb/client_impl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.

package ceresdb
/*
* Copyright 2022 The HoraeDB 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 horaedb

import (
"context"
Expand Down Expand Up @@ -28,7 +42,7 @@ func newClient(endpoint string, routeMode RouteMode, opts options) (Client, erro

func shouldClearRoute(err error) bool {
if err != nil {
if ceresdbErr, ok := err.(*Error); ok && ceresdbErr.ShouldClearRoute() {
if unwrapErr, ok := err.(*Error); ok && unwrapErr.ShouldClearRoute() {
return true
} else if strings.Contains(err.Error(), "connection error") {
// TODO: Find a better way to check if err means remote endpoint is down.
Expand Down
22 changes: 18 additions & 4 deletions ceresdb/code.go → horaedb/code.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.

package ceresdb
/*
* Copyright 2022 The HoraeDB 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 horaedb

import (
"errors"
Expand Down Expand Up @@ -35,7 +49,7 @@ type Error struct {
}

func (e *Error) Error() string {
return fmt.Sprintf("ceresdb rpc failed, code:%d, err:%s", e.Code, e.Err)
return fmt.Sprintf("HoraeDB RPC failed, code:%d, err:%s", e.Code, e.Err)
}

// TODO: may retry in sdk while code is 302 or 310
Expand Down
Loading