Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public ColumnMetadata(String name, Type type)
this(name, type, Optional.empty(), true, null, null, false, emptyMap());
}

private ColumnMetadata(
// VisibleForTesting
ColumnMetadata(
String name,
Type type,
Optional<String> defaultValue,
Expand Down Expand Up @@ -190,6 +191,7 @@ private Builder(ColumnMetadata columnMetadata)
{
this.name = columnMetadata.getName();
this.type = columnMetadata.getType();
this.defaultValue = columnMetadata.getDefaultValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just this.defaultValue = columnMetadata.getDefaultValue(); is enough (pushed a fix to your branch)

can you please add a test that Builder(ColumnMetada).build() roundtrips?

this.nullable = columnMetadata.isNullable();
this.comment = Optional.ofNullable(columnMetadata.getComment());
this.extraInfo = Optional.ofNullable(columnMetadata.getExtraInfo());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.spi.connector;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Test;

import java.util.Optional;

import static io.trino.spi.type.IntegerType.INTEGER;
import static org.assertj.core.api.Assertions.assertThat;

class TestColumnMetadata
{
@Test
public void testBuilderFrom()
{
ColumnMetadata originColumnMetadata = new ColumnMetadata(
"test_column",
INTEGER,
Optional.of("1"),
false,
"test_comment",
"test_extra_info",
false,
ImmutableMap.of("test_key", "test_value"));

ColumnMetadata buildColumnMetadata = ColumnMetadata.builderFrom(originColumnMetadata).build();

assertThat(buildColumnMetadata).isEqualTo(originColumnMetadata);
assertThat(buildColumnMetadata.getDefaultValue()).isEqualTo(originColumnMetadata.getDefaultValue());
assertThat(buildColumnMetadata.getProperties()).isEqualTo(originColumnMetadata.getProperties());
}
}