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

torand / FasterSQL / 16519063386

25 Jul 2025 09:48AM UTC coverage: 72.847% (+0.2%) from 72.681%
16519063386

push

github

torand
feat: add support for the 'ln', 'exp', 'sqrt' and 'power' math functions

230 of 372 branches covered (61.83%)

Branch coverage included in aggregate %.

63 of 76 new or added lines in 17 files covered. (82.89%)

1267 of 1683 relevant lines covered (75.28%)

3.97 hits per line

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

92.86
/src/main/java/io/github/torand/fastersql/function/singlerow/Exp.java
1
/*
2
 * Copyright (c) 2024-2025 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.alias.ColumnAlias;
19
import io.github.torand.fastersql.expression.Expression;
20
import io.github.torand.fastersql.model.Column;
21
import io.github.torand.fastersql.projection.Projection;
22
import io.github.torand.fastersql.sql.Context;
23

24
import java.util.Optional;
25
import java.util.stream.Stream;
26

27
import static io.github.torand.javacommons.contract.Requires.requireNonBlank;
28
import static io.github.torand.javacommons.lang.StringHelper.nonBlank;
29
import static java.util.Objects.requireNonNull;
30

31
/**
32
 * Implements the square root numeric function.
33
 */
34
public class Sqrt implements SingleRowFunction {
35
    private final Expression expression;
36
    private final ColumnAlias alias;
37

38
    Sqrt(Expression expression, String alias) {
2✔
39
        this.expression = requireNonNull(expression, "No expression specified");
6✔
40
        this.alias = nonBlank(alias) ? new ColumnAlias(alias) : defaultAlias();
12✔
41
    }
1✔
42

43
    // Sql
44

45
    @Override
46
    public String sql(Context context) {
47
        return "sqrt(%s)".formatted(expression.sql(context));
12✔
48
    }
49

50
    @Override
51
    public Stream<Object> params(Context context) {
52
        return expression.params(context);
5✔
53
    }
54

55
    @Override
56
    public Stream<Column> columnRefs() {
57
        return expression.columnRefs();
4✔
58
    }
59

60
    @Override
61
    public Stream<ColumnAlias> aliasRefs() {
NEW
62
        return expression.aliasRefs();
×
63
    }
64

65
    // Projection
66

67
    @Override
68
    public Projection as(String alias) {
69
        requireNonBlank(alias, "No alias specified");
6✔
70
        return new Sqrt(expression, alias);
7✔
71
    }
72

73
    @Override
74
    public Optional<ColumnAlias> alias() {
75
        return Optional.ofNullable(alias);
4✔
76
    }
77

78
    private ColumnAlias defaultAlias() {
79
        return ColumnAlias.generate("SQRT_");
3✔
80
    }
81
}
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