Skip to content

Commit

Permalink
code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJoiner committed May 10, 2024
1 parent 4b31730 commit 2a9dbe6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.22.x
go-version: 1.22

- name: Checkout code
uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions internal/graph/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Resolver struct {
*repositories.Repository
}

// getFloatArgs returns the complete arguments for the float signal query including arguments from the parent field.
func getFloatArgs(ctx context.Context, obj *model.SignalsWithID, agg model.FloatAggregation) (*repositories.FloatSignalArgs, error) {
args, err := getSignalArgs(ctx, obj)
if err != nil {
Expand All @@ -30,6 +31,7 @@ func getFloatArgs(ctx context.Context, obj *model.SignalsWithID, agg model.Float
}, nil
}

// getStringArgs returns the complete arguments for the string signal query including arguments from the parent field.
func getStringArgs(ctx context.Context, obj *model.SignalsWithID, agg model.StringAggregation) (*repositories.StringSignalArgs, error) {
args, err := getSignalArgs(ctx, obj)
if err != nil {
Expand Down Expand Up @@ -63,6 +65,7 @@ func getSignalArgs(ctx context.Context, obj *model.SignalsWithID) (*repositories
return args, nil
}

// getTimeArg returns the time argument from the args map.
func getTimeArg(args map[string]any, name string) time.Time {
val, ok := args[name]
if !ok {
Expand All @@ -75,6 +78,7 @@ func getTimeArg(args map[string]any, name string) time.Time {
return timeArg
}

// getFilterArg returns the filter argument from the args map.
func getFilterArg(args map[string]any) *model.SignalFilter {
filterArg, ok := args["filter"]
if !ok {
Expand Down
15 changes: 15 additions & 0 deletions internal/repositories/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var sourceTranslations = map[string]string{
}

var dialect = drivers.Dialect{
// Clickhouse does not like quotes around identifiers, so we set them to spaces since LQ and RQ are not optional.
LQ: ' ',
RQ: ' ',

Expand Down Expand Up @@ -125,6 +126,7 @@ func selectInterval(milliSeconds int64) qm.QueryMod {
return qm.Select(fmt.Sprintf("toStartOfInterval(Timestamp, toIntervalMillisecond(%d)) as %s", milliSeconds, IntervalGroup))
}

// returns a string representation of the aggregation function based on the aggregation type.
func getFloatAggFunc(aggType model.FloatAggregationType) string {
var aggStr string
switch aggType {
Expand All @@ -145,6 +147,7 @@ func getFloatAggFunc(aggType model.FloatAggregationType) string {
return aggStr
}

// returns a string representation of the aggregation function based on the aggregation type.
func getStringAgg(aggType model.StringAggregationType) string {
var aggStr string
switch aggType {
Expand Down Expand Up @@ -222,6 +225,18 @@ func getAggQuery(sigArgs SignalArgs, intervalMS int64, aggFunc string) (stmt str
return newQuery(mods...)
}

// creates a query to get the last seen timestamp of a token.
/*
SELECT
Timestamp
FROM
signal
WHERE
TokenID = ?
ORDER BY
Timestamp DESC
LIMIT 1;
*/
func getLastSeenQuery(sigArgs *SignalArgs) (stmt string, args []any) {
mods := []qm.QueryMod{
selectTimestamp(),
Expand Down

0 comments on commit 2a9dbe6

Please sign in to comment.