blob: 75e380d74c764ccf2889129b0ec9614fdd3fa56a [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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 horaedb
import (
"fmt"
)
func getTablesFromPoints(points []Point) []string {
dict := make(map[string]byte)
tables := make([]string, 0, len(points))
for _, point := range points {
if _, ok := dict[point.Table]; !ok {
dict[point.Table] = 0
tables = append(tables, point.Table)
}
}
return tables
}
func splitPointsByRoute(points []Point, routes map[string]route) (map[string][]Point, error) {
pointsByRoute := make(map[string][]Point, len(routes))
for _, point := range points {
route, ok := routes[point.Table]
if !ok {
return nil, fmt.Errorf("route for table %s not found", point.Table)
}
if rows, ok := pointsByRoute[route.Endpoint]; ok {
pointsByRoute[route.Endpoint] = append(rows, point)
} else {
pointsByRoute[route.Endpoint] = []Point{point}
}
}
return pointsByRoute, nil
}
func combineWriteResponse(r1 WriteResponse, r2 WriteResponse) WriteResponse {
r1.Success += r2.Success
r1.Failed += r2.Failed
return r1
}