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

torand / FasterSQL / 13591799490

28 Feb 2025 03:59PM UTC coverage: 65.237% (-1.3%) from 66.563%
13591799490

push

github

web-flow
Merge pull request #14 from torand/having-support

feat: supporting the HAVING clause + IS NULL operator now supports an…

214 of 408 branches covered (52.45%)

Branch coverage included in aggregate %.

273 of 389 new or added lines in 69 files covered. (70.18%)

3 existing lines in 3 files now uncovered.

1079 of 1574 relevant lines covered (68.55%)

3.68 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/singlerow/ToNumber.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.Column;
19
import io.github.torand.fastersql.Context;
20
import io.github.torand.fastersql.alias.ColumnAlias;
21
import io.github.torand.fastersql.expression.Expression;
22
import io.github.torand.fastersql.projection.Projection;
23

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

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

32
public class ToNumber implements SingleRowFunction {
33
    private final Expression expression;
34
    private final int precision;
35
    private final int scale;
36
    private final ColumnAlias alias;
37

38
    ToNumber(Expression expression, int precision, int scale, String alias) {
×
39
        require(() -> precision >= 1, "precision must be 1 or greater");
×
40
        require(() -> scale >= 0, "scale must be 0 or greater");
×
41
        require(() -> scale <= precision, "scale must be less than or equal to precision");
×
42

43
        this.expression = requireNonNull(expression, "No expression specified");
×
NEW
44
        this.alias = nonBlank(alias) ? new ColumnAlias(alias) : defaultAlias();
×
45
        this.precision = precision;
×
46
        this.scale = scale;
×
47
    }
×
48

49
    // Sql
50

51
    @Override
52
    public String sql(Context context) {
53
        return context.getDialect().formatToNumberFunction(expression.sql(context), precision, scale);
×
54
    }
55

56
    @Override
57
    public Stream<Object> params(Context context) {
58
        return expression.params(context);
×
59
    }
60

61
    @Override
62
    public Stream<Column> columnRefs() {
NEW
63
        return expression.columnRefs();
×
64
    }
65

66
    @Override
67
    public Stream<ColumnAlias> aliasRefs() {
NEW
68
        return expression.aliasRefs();
×
69
    }
70

71
    // Projection
72

73
    @Override
74
    public Projection as(String alias) {
75
        requireNonBlank(alias, "No alias specified");
×
76
        return new ToNumber(expression, precision, scale, alias);
×
77
    }
78

79
    @Override
80
    public Optional<ColumnAlias> alias() {
NEW
81
        return Optional.ofNullable(alias);
×
82
    }
83

84
    private ColumnAlias defaultAlias() {
NEW
85
        return ColumnAlias.generate("TO_NUMBER_");
×
86
    }
87
}
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