Skip to content

Commit

Permalink
delete query logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanbohan committed Jan 12, 2024
1 parent 098f379 commit d7b8559
Show file tree
Hide file tree
Showing 36 changed files with 506 additions and 2,902 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: golangci-lint
on: [push]

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
if: github.event.pull_request.draft == false
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.20.x'

- uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --timeout 10m -v

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2023 Greptime Team
Copyright 2024 Greptime Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/GreptimeTeam/greptimedb-client-go/blob/main/LICENSE)
[![Build Status](https://github.com/greptimeteam/greptimedb-client-go/actions/workflows/ci.yml/badge.svg)](https://github.com/GreptimeTeam/greptimedb-client-go/blob/main/.github/workflows/ci.yml)
[![codecov](https://codecov.io/gh/GreptimeTeam/greptimedb-client-go/branch/main/graph/badge.svg?token=76KIKITADQ)](https://codecov.io/gh/GreptimeTeam/greptimedb-client-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/GreptimeTeam/greptimedb-client-go.svg)](https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-client-go)
# GreptimeDB Go Client
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/GreptimeTeam/greptimedb-ingester-go/blob/main/LICENSE)
[![Build Status](https://github.com/greptimeteam/greptimedb-ingester-go/actions/workflows/ci.yml/badge.svg)](https://github.com/GreptimeTeam/greptimedb-ingester-go/blob/main/.github/workflows/ci.yml)
[![codecov](https://codecov.io/gh/GreptimeTeam/greptimedb-ingester-go/branch/main/graph/badge.svg?token=76KIKITADQ)](https://codecov.io/gh/GreptimeTeam/greptimedb-ingester-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/GreptimeTeam/greptimedb-ingester-go.svg)](https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-ingester-go)

# GreptimeDB Go Ingester

Provide API for using GreptimeDB client in Go.

## Installation

```sh
go get -u github.com/GreptimeTeam/greptimedb-client-go
go get -u github.com/GreptimeTeam/greptimedb-ingester-go
```

## Documentation
Expand All @@ -18,7 +19,7 @@ visit [docs](./docs) to get complete examples. You can also visit [Documentation

## API reference

#### Datatype Supported
### Datatype Supported

- int8, int16, int32, int64, int
- uint8, uint16, uint32, uint64, uint
Expand All @@ -28,7 +29,7 @@ visit [docs](./docs) to get complete examples. You can also visit [Documentation
- string
- time.Time

#### Customize metric Timestamp
### Customize metric Timestamp

you can customize timestamp index via calling methods of [Metric][metric_doc]

Expand All @@ -37,9 +38,9 @@ you can customize timestamp index via calling methods of [Metric][metric_doc]

## License

This greptimedb-client-go uses the __Apache 2.0 license__ to strike a balance
This greptimedb-ingester-go uses the __Apache 2.0 license__ to strike a balance
between open contributions and allowing you to use the software however you want.

<!-- links -->
[document]: https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-client-go
[metric_doc]: https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-client-go#Metric
[document]: https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-ingester-go
[metric_doc]: https://pkg.go.dev/github.com/GreptimeTeam/greptimedb-ingester-go#Metric
46 changes: 7 additions & 39 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Greptime Team
// Copyright 2024 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -20,13 +20,14 @@ import (
greptimepb "github.com/GreptimeTeam/greptime-proto/go/greptime/v1"
"github.com/apache/arrow/go/v13/arrow/flight"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

"github.com/GreptimeTeam/greptimedb-ingester-go/config"
)

// Client helps to Insert/Query data Into/From GreptimeDB. A Client is safe for concurrent
// use by multiple goroutines,you can have one Client instance in your application.
type Client struct {
cfg *Config
cfg *config.Config

// For `query`, since unary calls have not been implemented for query and only do_get helps
flightClient flight.Client
Expand All @@ -39,13 +40,13 @@ type Client struct {
}

// NewClient helps to create the greptimedb client, which will be responsible Write/Read data To/From GreptimeDB
func NewClient(cfg *Config) (*Client, error) {
flightClient, err := flight.NewClientWithMiddleware(cfg.getGRPCAddr(), nil, nil, cfg.DialOptions...)
func NewClient(cfg *config.Config) (*Client, error) {
flightClient, err := flight.NewClientWithMiddleware(cfg.GetGRPCAddr(), nil, nil, cfg.DialOptions...)
if err != nil {
return nil, err
}

conn, err := grpc.Dial(cfg.getGRPCAddr(), cfg.DialOptions...)
conn, err := grpc.Dial(cfg.GetGRPCAddr(), cfg.DialOptions...)
if err != nil {
return nil, err
}
Expand All @@ -69,36 +70,3 @@ func (c *Client) Insert(ctx context.Context, req InsertsRequest) (*greptimepb.Gr
}
return c.greptimeClient.Handle(ctx, request, c.cfg.CallOptions...)
}

// Query helps to retrieve data from greptimedb
func (c *Client) Query(ctx context.Context, req QueryRequest) (*Metric, error) {
request, err := req.buildGreptimeRequest(c.cfg)
if err != nil {
return nil, err
}

b, err := proto.Marshal(request)
if err != nil {
return nil, err
}
sr, err := c.flightClient.DoGet(ctx, &flight.Ticket{Ticket: b}, c.cfg.CallOptions...)
if err != nil {
return nil, err
}

reader, err := flight.NewRecordReader(sr)
if err != nil {
return nil, err
}

return buildMetricFromReader(reader)
}

// PromqlQuery helps to retrieve data from greptimedb via InstantQuery or RangeQuery
func (c *Client) PromqlQuery(ctx context.Context, req QueryRequest) (*greptimepb.PromqlResponse, error) {
request, err := req.buildPromqlRequest(c.cfg)
if err != nil {
return nil, err
}
return c.promqlClient.Handle(ctx, request, c.cfg.CallOptions...)
}
Loading

0 comments on commit d7b8559

Please sign in to comment.