Skip to content

Commit

Permalink
Fix inserting into Iceberg Parquet table with identifiers with quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
homar authored and ebyhr committed Jul 23, 2022
1 parent b60f388 commit fd82ae5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Expand Up @@ -82,7 +82,7 @@ private void visitRowType(RowType type, String name, List<String> parent)
parent = ImmutableList.<String>builder().addAll(parent).add(name).build();
for (RowType.Field field : type.getFields()) {
checkArgument(field.getName().isPresent(), "field in struct type doesn't have name");
visitType(field.getType(), field.getName().get(), parent);
visitType(field.getType(), makeCompatibleName(field.getName().get()), parent);
}
}
}
Expand Up @@ -4363,6 +4363,17 @@ public void testSelectWithMoreThanOneSnapshotOfTheSameTable()
assertUpdate(format("DROP TABLE %s", tableName));
}

@Test
public void testInsertingIntoTablesWithColumnsWithQuotesInName()
{
String tableName = "test_inserting_into_tables_with_quotes_" + randomTableSuffix();
assertUpdate(format("CREATE TABLE %s (\"an identifier with \"\"quotes\"\" \" INTEGER, x row (\"another identifier\" INTEGER))", tableName));
assertUpdate(format("INSERT INTO %s VALUES (1, row(11))", tableName), 1);
assertThat(query(format("SELECT * FROM %s", tableName)))
.matches("VALUES (INTEGER '1', CAST(ROW(11) AS ROW(\"another identifier\"INTEGER)))");
assertUpdate("DROP TABLE " + tableName);
}

@Override
protected OptionalInt maxTableNameLength()
{
Expand Down
@@ -0,0 +1,40 @@
/*
* 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.plugin.iceberg.util;

import com.google.common.collect.ImmutableList;
import io.trino.spi.type.RowType;
import io.trino.spi.type.Type;
import org.testng.annotations.Test;

import java.util.List;
import java.util.Map;
import java.util.Optional;

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

public class TestPrimitiveTypeMapBuilder
{
@Test
public void testMakeTypeMapProducesCorrectMapForTypesWithQuotes()
{
List<Type> inputTypes = ImmutableList.of(INTEGER, RowType.from(ImmutableList.of(new RowType.Field(Optional.of("another identifier"), INTEGER))));
List<String> inputColumnNames = ImmutableList.of("an identifier with \"quotes\" ", "a");

assertThat(PrimitiveTypeMapBuilder.makeTypeMap(inputTypes, inputColumnNames)).containsExactly(
Map.entry(ImmutableList.of("an_x20identifier_x20with_x20_x22quotes_x22_x20"), INTEGER),
Map.entry(ImmutableList.of("a", "another_x20identifier"), INTEGER));
}
}

0 comments on commit fd82ae5

Please sign in to comment.