Skip to content

Commit 33f3356

Browse files
aanejasumi-mathew
authored andcommitted
Enhance ShowColumns
to add three new columns : precision, scale and length test fix test fix
1 parent 5e2870a commit 33f3356

File tree

13 files changed

+157
-94
lines changed

13 files changed

+157
-94
lines changed

presto-base-arrow-flight/src/test/java/com/facebook/plugin/arrow/TestArrowFlightQueries.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.time.ZonedDateTime;
3838
import java.time.format.DateTimeFormatter;
3939

40+
import static com.facebook.presto.common.type.BigintType.BIGINT;
4041
import static com.facebook.presto.common.type.CharType.createCharType;
4142
import static com.facebook.presto.common.type.DateType.DATE;
4243
import static com.facebook.presto.common.type.IntegerType.INTEGER;
@@ -103,18 +104,18 @@ public void testShowCharColumns()
103104
{
104105
MaterializedResult actual = computeActual("SHOW COLUMNS FROM member");
105106

106-
MaterializedResult expectedUnparametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
107-
.row("id", "integer", "", "")
108-
.row("name", "varchar", "", "")
109-
.row("sex", "char", "", "")
110-
.row("state", "char", "", "")
107+
MaterializedResult expectedUnparametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
108+
.row("id", "integer", "", "", 10L, null, null)
109+
.row("name", "varchar", "", "", null, null, 2147483647L)
110+
.row("sex", "char", "", "", null, null, 2147483647L)
111+
.row("state", "char", "", "", null, null, 2147483647L)
111112
.build();
112113

113-
MaterializedResult expectedParametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
114-
.row("id", "integer", "", "")
115-
.row("name", "varchar(50)", "", "")
116-
.row("sex", "char(1)", "", "")
117-
.row("state", "char(5)", "", "")
114+
MaterializedResult expectedParametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
115+
.row("id", "integer", "", "", 10L, null, null)
116+
.row("name", "varchar(50)", "", "", null, null, 50L)
117+
.row("sex", "char(1)", "", "", null, null, 1L)
118+
.row("state", "char(5)", "", "", null, null, 5L)
118119
.build();
119120

120121
assertTrue(actual.equals(expectedParametrizedVarchar) || actual.equals(expectedUnparametrizedVarchar),
@@ -149,9 +150,11 @@ public void testSelectTime()
149150
public void testDescribeUnknownTable()
150151
{
151152
MaterializedResult actualRows = computeActual("DESCRIBE information_schema.enabled_roles");
152-
MaterializedResult expectedRows = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
153-
.row("role_name", "varchar", "", "")
153+
MaterializedResult expectedRows = resultBuilder(getSession(),
154+
VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
155+
.row("role_name", "varchar", "", "", null, null, 2147483647L)
154156
.build();
157+
155158
assertEquals(actualRows, expectedRows);
156159
}
157160

presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraIntegrationSmokeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void testUpperCaseNameUnescapedInCassandra()
279279
.row("table_1")
280280
.build(), new Duration(1, MINUTES));
281281
assertContains(execute("SHOW COLUMNS FROM cassandra.keyspace_1.table_1"), resultBuilder(getSession(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType())
282-
.row("column_1", "bigint", "", "")
282+
.row("column_1", "bigint", "", "", 10, null, null)
283283
.build());
284284

285285
execute("INSERT INTO keyspace_1.table_1 (column_1) VALUES (1)");
@@ -309,7 +309,7 @@ public void testUppercaseNameEscaped()
309309
.row("table_2")
310310
.build(), new Duration(1, MINUTES));
311311
assertContains(execute("SHOW COLUMNS FROM cassandra.keyspace_2.table_2"), resultBuilder(getSession(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType())
312-
.row("column_2", "bigint", "", "")
312+
.row("column_2", "bigint", "", "", 10, null, null)
313313
.build());
314314

315315
execute("INSERT INTO \"KEYSPACE_2\".\"TABLE_2\" (\"COLUMN_2\") VALUES (1)");

presto-hive/src/test/java/com/facebook/presto/hive/hudi/TestHudiIntegration.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import static com.facebook.presto.hive.hudi.HudiTestingDataGenerator.HUDI_META_COLUMNS;
3535
import static com.facebook.presto.hive.hudi.HudiTestingDataGenerator.PARTITION_COLUMNS;
3636
import static java.lang.String.format;
37+
import static java.util.Locale.ENGLISH;
3738

3839
public class TestHudiIntegration
3940
extends AbstractTestQueryFramework
@@ -151,10 +152,40 @@ public void testQueryOnUnavailablePartition()
151152
private static String generateDescribeIdenticalQuery(TypeManager typeManager, List<Column> metaColumns, List<Column> dataColumns, List<Column> partitionColumns)
152153
{
153154
Stream<String> regularRows = Streams.concat(metaColumns.stream(), dataColumns.stream())
154-
.map(column -> format("('%s', '%s', '', '')", column.getName(), column.getType().getType(typeManager).getDisplayName()));
155+
.map(column -> {
156+
String name = column.getName();
157+
String type = column.getType().getType(typeManager).getDisplayName();
158+
String size = getColumnSize(type);
159+
String length = type.toLowerCase(ENGLISH).equals("varchar") ? "2147483647" : "NULL";
160+
return format("('%s', '%s', '', '', %s, NULL, %s)", column.getName(), column.getType().getType(typeManager).getDisplayName(),
161+
getColumnSize(column.getType().getType(typeManager).getDisplayName()),
162+
(column.getType().getType(typeManager).getDisplayName()).toLowerCase(ENGLISH).equals("varchar") ? "2147483647" : "NULL");
163+
});
164+
155165
Stream<String> partitionRows = partitionColumns.stream()
156-
.map(column -> format("('%s', '%s', 'partition key', '')", column.getName(), column.getType().getType(typeManager).getDisplayName()));
157-
String rows = Streams.concat(regularRows, partitionRows).collect(Collectors.joining(","));
166+
.map(column -> {
167+
return format("('%s', '%s', 'partition key', '', %s, NULL, %s)", column.getName(),
168+
column.getType().getType(typeManager).getDisplayName(),
169+
getColumnSize(column.getType().getType(typeManager).getDisplayName()),
170+
(column.getType().getType(typeManager).getDisplayName()).toLowerCase(ENGLISH).equals("varchar") ? "2147483647" : "NULL");
171+
});
172+
173+
String rows = Streams.concat(regularRows, partitionRows)
174+
.collect(Collectors.joining(", "));
175+
158176
return "SELECT * FROM VALUES " + rows;
159177
}
178+
179+
private static String getColumnSize(String type)
180+
{
181+
switch (type.toLowerCase(ENGLISH)) {
182+
case "bigint":
183+
case "integer":
184+
return "10";
185+
case "double":
186+
return "2";
187+
default:
188+
return "NULL";
189+
}
190+
}
160191
}

presto-main-base/src/main/java/com/facebook/presto/connector/informationSchema/InformationSchemaMetadata.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public class InformationSchemaMetadata
9191
.column("data_type", createUnboundedVarcharType())
9292
.column("comment", createUnboundedVarcharType())
9393
.column("extra_info", createUnboundedVarcharType())
94+
.column("precision", BIGINT)
95+
.column("scale", BIGINT)
96+
.column("length", BIGINT)
9497
.build())
9598
.table(tableMetadataBuilder(TABLE_TABLES)
9699
.column("table_catalog", createUnboundedVarcharType())

presto-main-base/src/main/java/com/facebook/presto/connector/informationSchema/InformationSchemaPageSourceProvider.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import com.facebook.presto.common.Page;
1919
import com.facebook.presto.common.QualifiedObjectName;
2020
import com.facebook.presto.common.block.Block;
21+
import com.facebook.presto.common.type.CharType;
22+
import com.facebook.presto.common.type.Type;
23+
import com.facebook.presto.common.type.VarcharType;
2124
import com.facebook.presto.metadata.InternalTable;
2225
import com.facebook.presto.metadata.Metadata;
2326
import com.facebook.presto.metadata.QualifiedTablePrefix;
@@ -53,6 +56,8 @@
5356
import static com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.TABLE_TABLE_PRIVILEGES;
5457
import static com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.TABLE_VIEWS;
5558
import static com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.informationSchemaTableColumns;
59+
import static com.facebook.presto.connector.system.jdbc.ColumnJdbcTable.decimalDigits;
60+
import static com.facebook.presto.connector.system.jdbc.ColumnJdbcTable.numPrecRadix;
5661
import static com.facebook.presto.metadata.MetadataListing.listSchemas;
5762
import static com.facebook.presto.metadata.MetadataListing.listTableColumns;
5863
import static com.facebook.presto.metadata.MetadataListing.listTablePrivileges;
@@ -167,7 +172,10 @@ private InternalTable buildColumns(Session session, Set<QualifiedTablePrefix> pr
167172
column.isNullable() ? "YES" : "NO",
168173
column.getType().getDisplayName(),
169174
column.getComment().orElse(null),
170-
column.getExtraInfo().orElse(null));
175+
column.getExtraInfo().orElse(null),
176+
numPrecRadix(column.getType()),
177+
decimalDigits(column.getType()),
178+
getCharVarcharLength(column.getType()));
171179
ordinalPosition++;
172180
}
173181
}
@@ -281,4 +289,15 @@ private InternalTable buildEnabledRoles(Session session, String catalog)
281289
}
282290
return table.build();
283291
}
292+
293+
public static Integer getCharVarcharLength(Type type)
294+
{
295+
if (type instanceof VarcharType) {
296+
return ((VarcharType) type).getLength();
297+
}
298+
if (type instanceof CharType) {
299+
return (((CharType) type).getLength());
300+
}
301+
return null;
302+
}
284303
}

presto-main-base/src/main/java/com/facebook/presto/connector/system/jdbc/ColumnJdbcTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static Integer columnSize(Type type)
273273
}
274274

275275
// DECIMAL_DIGITS is the number of fractional digits
276-
private static Integer decimalDigits(Type type)
276+
public static Integer decimalDigits(Type type)
277277
{
278278
if (type instanceof DecimalType) {
279279
return ((DecimalType) type).getScale();
@@ -295,7 +295,7 @@ private static Integer charOctetLength(Type type)
295295
return null;
296296
}
297297

298-
static Integer numPrecRadix(Type type)
298+
public static Integer numPrecRadix(Type type)
299299
{
300300
if (type.equals(BIGINT) ||
301301
type.equals(INTEGER) ||

presto-main-base/src/main/java/com/facebook/presto/sql/rewrite/ShowQueriesRewrite.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ protected Node visitShowColumns(ShowColumns showColumns, Void context)
415415
aliasedName("column_name", "Column"),
416416
aliasedName("data_type", "Type"),
417417
aliasedNullToEmpty("extra_info", "Extra"),
418-
aliasedNullToEmpty("comment", "Comment")),
418+
aliasedNullToEmpty("comment", "Comment"),
419+
aliasedName("precision", "Precision"),
420+
aliasedName("scale", "Scale"),
421+
aliasedName("length", "Length")),
419422
from(tableName.getCatalogName(), TABLE_COLUMNS),
420423
logicalAnd(
421424
equal(identifier("table_schema"), new StringLiteral(tableName.getSchemaName())),

presto-product-tests/src/main/java/com/facebook/presto/tests/hive/TestHiveMixedCaseSupport.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ public void testCreateTablesWithMixedCaseNames()
9292
.containsOnly(row("testtable4"), row("testtable02"), row("testtable3"));
9393

9494
assertThat(query("DESCRIBE " + SCHEMA_NAME + ".testtable0"))
95-
.contains(row("name", "varchar(50)", "", ""), row("id", "integer", "", ""));
95+
.contains(row("name", "varchar(50)", "", "", null, null, 50L), row("id", "integer", "", "", 10L, null, null));
9696

9797
assertThat(query("DESCRIBE " + SCHEMA_NAME + ".testtable"))
98-
.contains(row("name", "varchar(50)", "", ""), row("id", "integer", "", ""));
98+
.contains(row("name", "varchar(50)", "", "", null, null, 50L), row("id", "integer", "", "", 10L, null, null));
9999

100100
assertThat(query("DESCRIBE " + SCHEMA_NAME_UPPER + ".testtable4"))
101-
.contains(row("name", "varchar(50)", "", ""), row("id", "integer", "", ""));
101+
.contains(row("name", "varchar(50)", "", "", null, null, 50L), row("id", "integer", "", "", 10L, null, null));
102102

103103
assertThat(query("DESCRIBE " + SCHEMA_NAME_UPPER + ".testtable02"))
104-
.contains(row("name", "varchar(50)", "", ""), row("id", "integer", "", ""), row("num", "double", "", ""));
104+
.contains(row("name", "varchar(50)", "", "", null, null, 50L), row("id", "integer", "", "", 10L, null, null), row("num", "double", "", "", 2L, null, null));
105105

106106
assertThat(() -> query("CREATE TABLE " + SCHEMA_NAME + ".TESTTABLE0 (name VARCHAR(50), id INT)"))
107107
.failsWithMessage(format("line 1:1: Table 'hive.%s.testtable0' already exists", SCHEMA_NAME));
@@ -156,21 +156,21 @@ public void testTableAlterWithMixedCaseNames()
156156
query("ALTER TABLE " + SCHEMA_NAME_UPPER + ".TESTTABLE02 ADD COLUMN num2 REAL");
157157

158158
assertThat(query("DESCRIBE " + SCHEMA_NAME + ".testtable"))
159-
.contains(row("num", "real", "", ""));
159+
.contains(row("num", "real", "", "", 2L, null, null));
160160
assertThat(query("DESCRIBE " + SCHEMA_NAME_UPPER + ".testtable02"))
161-
.contains(row("num1", "real", "", ""));
161+
.contains(row("num1", "real", "", "", 2L, null, null));
162162
assertThat(query("DESCRIBE " + SCHEMA_NAME + ".TESTTABLE2"))
163-
.contains(row("num01", "real", "", ""));
163+
.contains(row("num01", "real", "", "", 2L, null, null));
164164
assertThat(query("DESCRIBE " + SCHEMA_NAME_UPPER + ".TESTTABLE02"))
165-
.contains(row("num2", "real", "", ""));
165+
.contains(row("num2", "real", "", "", 2L, null, null));
166166

167167
query("ALTER TABLE " + SCHEMA_NAME + ".testtable RENAME COLUMN num TO numb");
168168
query("ALTER TABLE " + SCHEMA_NAME_UPPER + ".testtable02 RENAME COLUMN num1 TO numb01");
169169

170170
assertThat(query("DESCRIBE " + SCHEMA_NAME + ".testtable"))
171-
.contains(row("numb", "real", "", ""));
171+
.contains(row("numb", "real", "", "", 2L, null, null));
172172
assertThat(query("DESCRIBE " + SCHEMA_NAME_UPPER + ".testtable02"))
173-
.contains(row("numb01", "real", "", ""));
173+
.contains(row("numb01", "real", "", "", 2L, null, null));
174174
}
175175

176176
@Test(groups = {MIXED_CASE}, dependsOnMethods = "testTableAlterWithMixedCaseNames")

presto-singlestore/src/test/java/com/facebook/presto/plugin/singlestore/TestSingleStoreDistributedQueries.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.testng.annotations.AfterClass;
2222
import org.testng.annotations.Test;
2323

24+
import static com.facebook.presto.common.type.BigintType.BIGINT;
2425
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
2526
import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
2627
import static com.facebook.presto.testing.assertions.Assert.assertEquals;
@@ -64,16 +65,16 @@ public void testShowColumns()
6465
{
6566
MaterializedResult actual = computeActual("SHOW COLUMNS FROM orders");
6667

67-
MaterializedResult expectedParametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
68-
.row("orderkey", "bigint", "", "")
69-
.row("custkey", "bigint", "", "")
70-
.row("orderstatus", "varchar(85)", "", "")//utf8
71-
.row("totalprice", "double", "", "")
72-
.row("orderdate", "date", "", "")
73-
.row("orderpriority", "varchar(85)", "", "")
74-
.row("clerk", "varchar(85)", "", "")
75-
.row("shippriority", "integer", "", "")
76-
.row("comment", "varchar(85)", "", "")
68+
MaterializedResult expectedParametrizedVarchar = resultBuilder(getSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
69+
.row("orderkey", "bigint", "", "", 10L, null, null)
70+
.row("custkey", "bigint", "", "", 10L, null, null)
71+
.row("orderstatus", "varchar(85)", "", "", null, null, 85L)//utf8
72+
.row("totalprice", "double", "", "", 2L, null, null)
73+
.row("orderdate", "date", "", "", null, null, null)
74+
.row("orderpriority", "varchar(85)", "", "", null, null, 85L)
75+
.row("clerk", "varchar(85)", "", "", null, null, 85L)
76+
.row("shippriority", "integer", "", "", 10L, null, null)
77+
.row("comment", "varchar(85)", "", "", null, null, 85L)
7778
.build();
7879

7980
assertEquals(actual, expectedParametrizedVarchar);

presto-singlestore/src/test/java/com/facebook/presto/plugin/singlestore/TestSingleStoreIntegrationSmokeTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.sql.Statement;
2929
import java.util.Map;
3030

31+
import static com.facebook.presto.common.type.BigintType.BIGINT;
3132
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
3233
import static com.facebook.presto.testing.assertions.Assert.assertEquals;
3334
import static io.airlift.tpch.TpchTable.ORDERS;
@@ -65,16 +66,16 @@ public void testDescribeTable()
6566
// we need specific implementation of this tests due to specific Presto<->SingleStore varchar length mapping.
6667
MaterializedResult actualColumns = computeActual("DESC ORDERS").toTestTypes();
6768

68-
MaterializedResult expectedColumns = MaterializedResult.resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR)
69-
.row("orderkey", "bigint", "", "")
70-
.row("custkey", "bigint", "", "")
71-
.row("orderstatus", "varchar(85)", "", "")//utf-8
72-
.row("totalprice", "double", "", "")
73-
.row("orderdate", "date", "", "")
74-
.row("orderpriority", "varchar(85)", "", "")
75-
.row("clerk", "varchar(85)", "", "")
76-
.row("shippriority", "integer", "", "")
77-
.row("comment", "varchar(85)", "", "")
69+
MaterializedResult expectedColumns = MaterializedResult.resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR, BIGINT, BIGINT, BIGINT)
70+
.row("orderkey", "bigint", "", "", 10L, null, null)
71+
.row("custkey", "bigint", "", "", 10L, null, null)
72+
.row("orderstatus", "varchar(85)", "", "", null, null, 85L)//utf-8
73+
.row("totalprice", "double", "", "", 2L, null, null)
74+
.row("orderdate", "date", "", "", null, null, null)
75+
.row("orderpriority", "varchar(85)", "", "", null, null, 85L)
76+
.row("clerk", "varchar(85)", "", "", null, null, 85L)
77+
.row("shippriority", "integer", "", "", 10L, null, null)
78+
.row("comment", "varchar(85)", "", "", null, null, 85L)
7879
.build();
7980
assertEquals(actualColumns, expectedColumns);
8081
}

0 commit comments

Comments
 (0)