This is an automated email from the ASF dual-hosted git repository.

jerryshao pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-1.3 by this push:
     new f5ce538594 [Cherry-pick to branch-1.3] [#14729] fix(doris): Preserve 
LARGEINT column metadata (#14730) (#14768)
f5ce538594 is described below

commit f5ce538594ec37b9ce68662b11445b0a070c9da0
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Nov 9 15:46:40 2026 +0800

    [Cherry-pick to branch-1.3] [#14729] fix(doris): Preserve LARGEINT column 
metadata (#14730) (#14768)
    
    **Cherry-pick Information:**
    - Original commit: 63ea32307ed5ab5a6c71880fbe8f4bcecd5d177d
    - Target branch: `branch-1.3`
    - The cherry-pick applied without text conflicts. An additional
    `java.util.HashSet` import is required on this branch: main already had
    it before the original commit, so it was absent from the cherry-pick
    patch.
    
    **Validation:**
    - Fixed the `DorisTableOperations` compilation error (`cannot find
    symbol: class HashSet`).
    - Passed Doris source/test compilation, Spotless, and `git diff
    --check`.
    - Passed 39 targeted tests for column metadata, type/default conversion,
    and Doris 1.2 table operations, including a real LARGEINT round trip
    preserving a 128-bit default; no tests skipped.
    
    ---------
    
    Co-authored-by: Qi Yu <[email protected]>
    Co-authored-by: yuqi <[email protected]>
---
 .../doris/operation/DorisTableOperations.java      |  61 ++++++
 .../doris/operation/TestDorisColumnMetadata.java   | 228 +++++++++++++++++++++
 .../doris/operation/TestDorisTableOperations.java  |  38 ++++
 docs/jdbc-doris-catalog.md                         |   3 +
 4 files changed, 330 insertions(+)

diff --git 
a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java
 
b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java
index 24ce6ae61f..cfb7a9a2e5 100644
--- 
a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java
+++ 
b/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java
@@ -39,6 +39,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -48,6 +49,8 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.RowSetProvider;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.BooleanUtils;
@@ -757,6 +760,64 @@ public class DorisTableOperations extends 
JdbcTableOperations {
     }
   }
 
+  /** {@inheritDoc} */
+  @Override
+  protected ResultSet getColumns(Connection connection, String databaseName, 
String tableName)
+      throws SQLException {
+    CachedRowSet columns = RowSetProvider.newFactory().createCachedRowSet();
+    try {
+      try (ResultSet metadata = super.getColumns(connection, databaseName, 
tableName)) {
+        columns.populate(metadata);
+      }
+
+      // Doris 1.2 can expose LARGEINT as INT through MySQL JDBC metadata. 
Only query native
+      // types when the target table has an INT column that may need 
correction.
+      boolean hasIntColumn = false;
+      while (columns.next()) {
+        // JDBC treats underscores and percent signs in table names as 
wildcard patterns.
+        if (tableName.equals(columns.getString("TABLE_NAME"))
+            && "INT".equalsIgnoreCase(columns.getString("TYPE_NAME"))) {
+          hasIntColumn = true;
+          break;
+        }
+      }
+      columns.beforeFirst();
+      if (!hasIntColumn) {
+        return columns;
+      }
+
+      // Restore the native type before converting both the column type and 
its default value.
+      Set<String> largeIntColumns = new HashSet<>();
+      String sql =
+          "SELECT COLUMN_NAME, COLUMN_TYPE FROM information_schema.COLUMNS"
+              + " WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?";
+      try (PreparedStatement statement = connection.prepareStatement(sql)) {
+        statement.setString(1, databaseName);
+        statement.setString(2, tableName);
+        try (ResultSet result = statement.executeQuery()) {
+          while (result.next()) {
+            if ("largeint".equalsIgnoreCase(result.getString("COLUMN_TYPE"))) {
+              largeIntColumns.add(result.getString("COLUMN_NAME"));
+            }
+          }
+        }
+      }
+      while (columns.next()) {
+        // JDBC treats underscores and percent signs in table names as 
wildcard patterns.
+        if (tableName.equals(columns.getString("TABLE_NAME"))
+            && largeIntColumns.contains(columns.getString("COLUMN_NAME"))) {
+          columns.updateString("TYPE_NAME", "largeint");
+          columns.updateRow();
+        }
+      }
+      columns.beforeFirst();
+      return columns;
+    } catch (SQLException | RuntimeException e) {
+      columns.close();
+      throw e;
+    }
+  }
+
   @Override
   protected void correctJdbcTableFields(
       Connection connection, String databaseName, String tableName, 
JdbcTable.Builder tableBuilder)
diff --git 
a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisColumnMetadata.java
 
b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisColumnMetadata.java
new file mode 100644
index 0000000000..1fb5f09cc5
--- /dev/null
+++ 
b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisColumnMetadata.java
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.gravitino.catalog.doris.operation;
+
+import static java.sql.Types.VARCHAR;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.RowSetMetaDataImpl;
+import javax.sql.rowset.RowSetProvider;
+import 
org.apache.gravitino.catalog.doris.converter.DorisColumnDefaultValueConverter;
+import org.apache.gravitino.catalog.doris.converter.DorisTypeConverter;
+import org.apache.gravitino.catalog.jdbc.JdbcColumn;
+import org.apache.gravitino.rel.expressions.UnparsedExpression;
+import org.apache.gravitino.rel.types.Types;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class TestDorisColumnMetadata {
+  @ParameterizedTest
+  @ValueSource(strings = {"INT", "int"})
+  void testNativeLargeIntTypeBeforeDefaultConversion(String jdbcIntType) 
throws Exception {
+    Connection connection = mock(Connection.class);
+    DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+    when(connection.getMetaData()).thenReturn(metadata);
+    CachedRowSet jdbcColumns = columns();
+    addColumn(
+        jdbcColumns,
+        "target_table",
+        "large",
+        jdbcIntType,
+        "170141183460469231731687303715884105727");
+    addColumn(jdbcColumns, "target_table", "regular_int", jdbcIntType, "7");
+    addColumn(jdbcColumns, "target_table", "regular_long", "BIGINT", "8");
+    addColumn(jdbcColumns, "target_table", "unsigned_long", "BIGINT UNSIGNED", 
null);
+    addColumn(jdbcColumns, "targetXtable", "large", "INT", "9");
+    jdbcColumns.beforeFirst();
+    when(metadata.getColumns(null, null, "target_table", 
null)).thenReturn(jdbcColumns);
+
+    PreparedStatement statement = mock(PreparedStatement.class);
+    ResultSet nativeColumns = mock(ResultSet.class);
+    when(connection.prepareStatement(anyString())).thenReturn(statement);
+    when(statement.executeQuery()).thenReturn(nativeColumns);
+    when(nativeColumns.next()).thenReturn(true, true, true, true, false);
+    when(nativeColumns.getString("COLUMN_NAME"))
+        .thenReturn("large", "regular_int", "regular_long", "unsigned_long");
+    when(nativeColumns.getString("COLUMN_TYPE"))
+        .thenReturn("LARGEINT", "int", "bigint", "bigint unsigned");
+
+    TestableOperations operations = new TestableOperations();
+    try (ResultSet result = operations.readMetadata(connection, "db", 
"target_table")) {
+      Map<String, JdbcColumn> loaded = new HashMap<>();
+      while (result.next()) {
+        if ("targetXtable".equals(result.getString("TABLE_NAME"))) {
+          assertEquals("INT", result.getString("TYPE_NAME"));
+        } else {
+          JdbcColumn column = operations.readColumn(result);
+          loaded.put(column.name(), column);
+        }
+      }
+      JdbcColumn large = loaded.get("large");
+      assertEquals(Types.ExternalType.of("largeint"), large.dataType());
+      assertEquals(
+          UnparsedExpression.of("170141183460469231731687303715884105727"), 
large.defaultValue());
+      assertEquals("column comment", large.comment());
+      assertTrue(large.nullable());
+      assertTrue(large.autoIncrement());
+      assertEquals(Types.IntegerType.get(), 
loaded.get("regular_int").dataType());
+      assertEquals(Types.LongType.get(), 
loaded.get("regular_long").dataType());
+      assertEquals(
+          Types.ExternalType.of("bigint unsigned"), 
loaded.get("unsigned_long").dataType());
+    }
+    verify(statement).setString(1, "db");
+    verify(statement).setString(2, "target_table");
+    verify(connection, times(1)).prepareStatement(anyString());
+    verify(nativeColumns).close();
+    verify(statement).close();
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {"BIGINT", "LARGEINT", "INT UNSIGNED", "SMALLINT", 
"VARCHAR"})
+  void testNativeMetadataLookupSkippedWithoutIntColumns(String type) throws 
Exception {
+    Connection connection = mock(Connection.class);
+    DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+    when(connection.getMetaData()).thenReturn(metadata);
+    CachedRowSet jdbcColumns = columns();
+    addColumn(jdbcColumns, "target_table", "value", type, "7");
+    // A table matched only by the JDBC wildcard must not trigger a native 
metadata lookup.
+    addColumn(jdbcColumns, "targetXtable", "other_value", "INT", "9");
+    jdbcColumns.beforeFirst();
+    when(metadata.getColumns(null, null, "target_table", 
null)).thenReturn(jdbcColumns);
+
+    try (ResultSet result =
+        new TestableOperations().readMetadata(connection, "db", 
"target_table")) {
+      Map<String, String> loaded = new HashMap<>();
+      while (result.next()) {
+        loaded.put(result.getString("COLUMN_NAME"), 
result.getString("TYPE_NAME"));
+        if ("target_table".equals(result.getString("TABLE_NAME"))) {
+          assertEquals("7", result.getString("COLUMN_DEF"));
+          assertEquals("column comment", result.getString("REMARKS"));
+        }
+      }
+      assertEquals(Map.of("value", type, "other_value", "INT"), loaded);
+    }
+    verify(connection, never()).prepareStatement(anyString());
+  }
+
+  @Test
+  void testNativeMetadataLookupSkippedForEmptyColumns() throws Exception {
+    Connection connection = mock(Connection.class);
+    DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+    when(connection.getMetaData()).thenReturn(metadata);
+    when(metadata.getColumns(null, null, "t", null)).thenReturn(columns());
+
+    try (ResultSet result = new TestableOperations().readMetadata(connection, 
"db", "t")) {
+      assertFalse(result.next());
+    }
+    verify(connection, never()).prepareStatement(anyString());
+  }
+
+  @Test
+  void testNativeMetadataFailurePropagates() throws Exception {
+    Connection connection = mock(Connection.class);
+    DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+    when(connection.getMetaData()).thenReturn(metadata);
+    CachedRowSet jdbcColumns = columns();
+    addColumn(jdbcColumns, "t", "value", "INT", "7");
+    jdbcColumns.beforeFirst();
+    when(metadata.getColumns(null, null, "t", null)).thenReturn(jdbcColumns);
+    SQLException failure = new SQLException("metadata unavailable");
+    when(connection.prepareStatement(anyString())).thenThrow(failure);
+    assertSame(
+        failure,
+        assertThrows(
+            SQLException.class,
+            () -> new TestableOperations().readMetadata(connection, "db", 
"t")));
+  }
+
+  private static CachedRowSet columns() throws SQLException {
+    String[] names = {
+      "TABLE_NAME",
+      "COLUMN_NAME",
+      "TYPE_NAME",
+      "COLUMN_SIZE",
+      "DECIMAL_DIGITS",
+      "REMARKS",
+      "NULLABLE",
+      "COLUMN_DEF",
+      "IS_GENERATEDCOLUMN",
+      "IS_AUTOINCREMENT"
+    };
+    RowSetMetaDataImpl metadata = new RowSetMetaDataImpl();
+    metadata.setColumnCount(names.length);
+    for (int i = 0; i < names.length; i++) {
+      metadata.setColumnName(i + 1, names[i]);
+      metadata.setColumnType(i + 1, VARCHAR);
+    }
+    CachedRowSet result = RowSetProvider.newFactory().createCachedRowSet();
+    result.setMetaData(metadata);
+    return result;
+  }
+
+  private static void addColumn(
+      CachedRowSet rows, String table, String name, String type, String 
defaultValue)
+      throws SQLException {
+    rows.moveToInsertRow();
+    String[] values = {
+      table, name, type, "39", "0", "column comment", "1", defaultValue, "NO", 
"YES"
+    };
+    for (int i = 0; i < values.length; i++) {
+      rows.updateString(i + 1, values[i]);
+    }
+    rows.insertRow();
+    rows.moveToCurrentRow();
+  }
+
+  private static class TestableOperations extends DorisTableOperations {
+    private TestableOperations() {
+      typeConverter = new DorisTypeConverter();
+      columnDefaultValueConverter = new DorisColumnDefaultValueConverter();
+    }
+
+    private ResultSet readMetadata(Connection connection, String database, 
String table)
+        throws SQLException {
+      return getColumns(connection, database, table);
+    }
+
+    private JdbcColumn readColumn(ResultSet result) throws SQLException {
+      return getColumnBuilder(result, "db", "target_table")
+          .withAutoIncrement(getAutoIncrementInfo(result))
+          .build();
+    }
+  }
+}
diff --git 
a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java
 
b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java
index 0ccf7d0290..1346a7d846 100644
--- 
a/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java
+++ 
b/catalogs/catalog-jdbc-doris/src/test/java/org/apache/gravitino/catalog/doris/operation/TestDorisTableOperations.java
@@ -46,6 +46,7 @@ import org.apache.gravitino.rel.Column;
 import org.apache.gravitino.rel.TableChange;
 import org.apache.gravitino.rel.expressions.Expression;
 import org.apache.gravitino.rel.expressions.NamedReference;
+import org.apache.gravitino.rel.expressions.UnparsedExpression;
 import org.apache.gravitino.rel.expressions.distributions.Distribution;
 import org.apache.gravitino.rel.expressions.distributions.Distributions;
 import org.apache.gravitino.rel.expressions.literals.Literal;
@@ -103,6 +104,43 @@ public class TestDorisTableOperations extends TestDoris {
     return properties;
   }
 
+  @Test
+  void testLargeIntMetadataRoundTrip() {
+    String tableName = GravitinoITUtils.genRandomName("doris_largeint");
+    String largeDefault = "170141183460469231731687303715884105727";
+    JdbcColumn[] columns = {
+      
JdbcColumn.builder().withName("id").withType(INT).withNullable(false).build(),
+      JdbcColumn.builder()
+          .withName("large_value")
+          .withType(Types.ExternalType.of("largeint"))
+          .withComment("128-bit value")
+          .withNullable(true)
+          .withDefaultValue(Literals.stringLiteral(largeDefault))
+          .build(),
+      
JdbcColumn.builder().withName("long_value").withType(Types.LongType.get()).build()
+    };
+    TABLE_OPERATIONS.create(
+        databaseName,
+        tableName,
+        columns,
+        "largeint metadata",
+        createProperties(),
+        Transforms.EMPTY_TRANSFORM,
+        Distributions.hash(DEFAULT_BUCKET_SIZE, NamedReference.field("id")),
+        Indexes.EMPTY_INDEXES);
+    try {
+      Column[] loaded = TABLE_OPERATIONS.load(databaseName, 
tableName).columns();
+      Assertions.assertEquals(INT, loaded[0].dataType());
+      Assertions.assertEquals(Types.ExternalType.of("largeint"), 
loaded[1].dataType());
+      Assertions.assertEquals(UnparsedExpression.of(largeDefault), 
loaded[1].defaultValue());
+      Assertions.assertEquals("128-bit value", loaded[1].comment());
+      Assertions.assertTrue(loaded[1].nullable());
+      Assertions.assertEquals(Types.LongType.get(), loaded[2].dataType());
+    } finally {
+      TABLE_OPERATIONS.drop(databaseName, tableName);
+    }
+  }
+
   @Test
   void testAllDistribution() {
     Distribution[] distributions =
diff --git a/docs/jdbc-doris-catalog.md b/docs/jdbc-doris-catalog.md
index 49e576aceb..4f448bcf94 100644
--- a/docs/jdbc-doris-catalog.md
+++ b/docs/jdbc-doris-catalog.md
@@ -158,11 +158,14 @@ Doris doesn't support Gravitino `Fixed` `Timestamp_tz` 
`IntervalDay` `IntervalYe
 The data types other than those listed above are mapped to Gravitino's 
**[Unparsed Type](./tables-and-views.md#unparsed-type)** that represents an 
unresolvable data type.
 
 :::note
+The table above describes type mappings; it does not guarantee that every type 
can be used to create a table through Gravitino. `BITMAP` and `HLL` columns are 
supported only when loading metadata for existing Doris tables. Creating tables 
with these column types through Gravitino is not supported.
+
 Doris `array`, `map`, and `struct` types are loaded as `ExternalType` with the 
full type string preserved (e.g. `array<int(11)>`). They are not resolved into 
Gravitino native composite types (`ListType`, `MapType`, `StructType`). The 
type identifier in `ExternalType` is always lowercase (e.g. `"json"`, not 
`"JSON"`), matching Doris JDBC metadata behavior.
 :::
 
 :::tip Version Compatibility
 - `DateV2` type: Doris 1.2+ (required on 4.0.x where `disable_datev1=true`)
+- `JSON` type name: Doris 2.0+; Doris 1.2 uses `JSONB`, so 
`ExternalType("json")` cannot be used to create a JSON column on Doris 1.2.
 - `Binary` / `VarBinary` type: Doris 4.0+ (not available on 3.x)
 - `Auto-Increment` column: Doris 2.1+
 - `INVERTED` index: Doris 3.0+

Reply via email to