• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / FasterSQL / 12970605210

26 Jan 2025 02:26AM UTC coverage: 45.768% (-0.4%) from 46.173%
12970605210

push

github

torand
feat: support avg function

108 of 334 branches covered (32.34%)

Branch coverage included in aggregate %.

0 of 12 new or added lines in 2 files covered. (0.0%)

622 of 1261 relevant lines covered (49.33%)

2.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/io/github/torand/fastersql/function/aggregate/Avg.java
1
/*
2
 * Copyright (c) 2024 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.function.aggregate;
17

18
import io.github.torand.fastersql.Context;
19
import io.github.torand.fastersql.Field;
20
import io.github.torand.fastersql.projection.Projection;
21

22
import java.util.stream.Stream;
23

24
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
25
import static io.github.torand.fastersql.util.lang.StringHelper.nonBlank;
26
import static java.util.Objects.requireNonNull;
27

28
public class Avg implements AggregateFunction {
29
    private final Field field;
30
    private final String alias;
31

NEW
32
    Avg(Field field, String alias) {
×
NEW
33
        this.field = requireNonNull(field, "No field specified");
×
NEW
34
        this.alias = nonBlank(alias) ? alias : defaultAlias(field);
×
NEW
35
    }
×
36

37
    // Sql
38

39
    @Override
40
    public String sql(Context context) {
NEW
41
        return "avg(" + field.sql(context) + ")";
×
42
    }
43

44
    @Override
45
    public Stream<Object> params(Context context) {
NEW
46
        return Stream.empty();
×
47
    }
48

49
    // Projection
50

51
    @Override
52
    public Projection as(String alias) {
NEW
53
        requireNonBlank(alias, "No alias specified");
×
NEW
54
        return new Avg(field, alias);
×
55
    }
56

57
    @Override
58
    public String alias() {
NEW
59
        return alias;
×
60
    }
61

62
    // Expression
63

64
    @Override
65
    public Stream<Field> fieldRefs() {
NEW
66
        return Stream.of(field);
×
67
    }
68

69
    private String defaultAlias(Field field) {
NEW
70
        return "AVG_" + field.alias();
×
71
    }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc