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

torand / FasterSQL / 13367709795

17 Feb 2025 10:06AM UTC coverage: 58.785% (+2.0%) from 56.762%
13367709795

push

github

torand
feat: support length function

148 of 338 branches covered (43.79%)

Branch coverage included in aggregate %.

10 of 17 new or added lines in 7 files covered. (58.82%)

66 existing lines in 9 files now uncovered.

829 of 1324 relevant lines covered (62.61%)

3.33 hits per line

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

69.23
/src/main/java/io/github/torand/fastersql/function/singlerow/Length.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.singlerow;
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 io.github.torand.fastersql.util.lang.StringHelper.nonBlank;
28
import static java.util.Objects.requireNonNull;
29

30
public class Length implements SingleRowFunction {
31
    private final Expression expression;
32
    private final String alias;
33

34
    Length(Expression expression, String alias) {
2✔
35
        this.expression = requireNonNull(expression, "No expression specified");
6✔
36
        this.alias = nonBlank(alias) ? alias : defaultAlias();
7!
37
    }
1✔
38

39
    // Sql
40

41
    @Override
42
    public String sql(Context context) {
43
        return context.getDialect().formatLengthFunction(expression.sql(context));
8✔
44
    }
45

46
    @Override
47
    public Stream<Object> params(Context context) {
48
        return expression.params(context);
5✔
49
    }
50

51
    // Projection
52

53
    @Override
54
    public Projection as(String alias) {
NEW
55
        requireNonBlank(alias, "No alias specified");
×
NEW
56
        return new Length(expression, alias);
×
57
    }
58

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

64
    // Expression
65

66
    @Override
67
    public Stream<Field> fieldRefs() {
68
        return expression.fieldRefs();
4✔
69
    }
70

71
    private String defaultAlias() {
72
        return "LENGTH_" + new Random().nextInt(999) + 1;
7✔
73
    }
74
}
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