Skip to content

Commit de3fbce

Browse files
committed
Add missing defaultValue for ColumnMetadata.Builder
1 parent ed1b468 commit de3fbce

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

core/trino-spi/src/main/java/io/trino/spi/connector/ColumnMetadata.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public ColumnMetadata(String name, Type type)
4343
this(name, type, Optional.empty(), true, null, null, false, emptyMap());
4444
}
4545

46-
private ColumnMetadata(
46+
// VisibleForTesting
47+
ColumnMetadata(
4748
String name,
4849
Type type,
4950
Optional<String> defaultValue,
@@ -190,6 +191,7 @@ private Builder(ColumnMetadata columnMetadata)
190191
{
191192
this.name = columnMetadata.getName();
192193
this.type = columnMetadata.getType();
194+
this.defaultValue = columnMetadata.getDefaultValue();
193195
this.nullable = columnMetadata.isNullable();
194196
this.comment = Optional.ofNullable(columnMetadata.getComment());
195197
this.extraInfo = Optional.ofNullable(columnMetadata.getExtraInfo());
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.spi.connector;
15+
16+
import com.google.common.collect.ImmutableMap;
17+
import org.junit.jupiter.api.Test;
18+
19+
import java.util.Optional;
20+
21+
import static io.trino.spi.type.IntegerType.INTEGER;
22+
import static org.assertj.core.api.Assertions.assertThat;
23+
24+
class TestColumnMetadata
25+
{
26+
@Test
27+
public void testBuilderFrom()
28+
{
29+
ColumnMetadata originColumnMetadata = new ColumnMetadata(
30+
"test_column",
31+
INTEGER,
32+
Optional.of("1"),
33+
false,
34+
"test_comment",
35+
"test_extra_info",
36+
false,
37+
ImmutableMap.of("test_key", "test_value"));
38+
39+
ColumnMetadata buildColumnMetadata = ColumnMetadata.builderFrom(originColumnMetadata).build();
40+
41+
assertThat(buildColumnMetadata).isEqualTo(originColumnMetadata);
42+
assertThat(buildColumnMetadata.getDefaultValue()).isEqualTo(originColumnMetadata.getDefaultValue());
43+
assertThat(buildColumnMetadata.getProperties()).isEqualTo(originColumnMetadata.getProperties());
44+
}
45+
}

0 commit comments

Comments
 (0)