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

torand / FasterSQL / 13316820294

13 Feb 2025 08:49PM UTC coverage: 56.762% (+11.0%) from 45.739%
13316820294

push

github

web-flow
Merge pull request #8 from torand/testcontainers

feat: misc additions

143 of 336 branches covered (42.56%)

Branch coverage included in aggregate %.

97 of 171 new or added lines in 34 files covered. (56.73%)

6 existing lines in 6 files now uncovered.

772 of 1276 relevant lines covered (60.5%)

3.21 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/Count.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.expression.Expression;
21
import io.github.torand.fastersql.projection.Projection;
22

23
import java.util.Random;
24
import java.util.stream.Stream;
25

26
import static io.github.torand.fastersql.util.contract.Requires.requireNonBlank;
27
import static java.util.Objects.nonNull;
28
import static java.util.Objects.requireNonNull;
29

30
/**
31
 * Returns number rows where expression is not evaluated tp null
32
 */
33
public class Count implements AggregateFunction {
34
    private final Expression expression;
35
    private final String alias;
36

NEW
37
    Count(Expression expression, String alias) {
×
NEW
38
        this.expression = requireNonNull(expression, "No expression specified");
×
NEW
39
        this.alias = nonNull(alias) ? alias : defaultAlias();
×
UNCOV
40
    }
×
41

42
    // Sql
43

44
    @Override
45
    public String sql(Context context) {
NEW
46
        return "count(" + expression.sql(context) + ")";
×
47
    }
48

49
    @Override
50
    public Stream<Object> params(Context context) {
NEW
51
        return expression.params(context);
×
52
    }
53

54
    // Projection
55

56
    @Override
57
    public Projection as(String alias) {
58
        requireNonBlank(alias, "No alias specified");
×
NEW
59
        return new Count(expression, alias);
×
60
    }
61

62
    @Override
63
    public String alias() {
64
        return alias;
×
65
    }
66

67
    // Expression
68

69
    @Override
70
    public Stream<Field> fieldRefs() {
NEW
71
        return expression.fieldRefs();
×
72
    }
73

74
    private String defaultAlias() {
NEW
75
        return "COUNT_" + new Random().nextInt(999) + 1;
×
76
    }
77
}
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