This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 4ed1f21a67f [feature](hive) Support LzoTextInputFormat and
DeprecatedLzoTextInputFormat in Hive Catalog (#62439)
4ed1f21a67f is described below
commit 4ed1f21a67f87f04ce31de92a87cac26ab056a48
Author: zhaorongsheng <[email protected]>
AuthorDate: Tue Apr 21 01:45:26 2026 +0800
[feature](hive) Support LzoTextInputFormat and DeprecatedLzoTextInputFormat
in Hive Catalog (#62439)
### What problem does this PR solve?
Issue Number: close #62465
Related PR: N/A
Problem Summary:
When a Hive table is created with
`com.hadoop.compression.lzo.LzoTextInputFormat`
or `com.hadoop.mapred.DeprecatedLzoTextInputFormat` as the InputFormat,
Doris
Hive Catalog throws `NotSupportedException` and cannot query the table.
Two FE-side fixes are applied:
1. **HMSExternalTable.java** – Add both InputFormats to
`SUPPORTED_HIVE_FILE_FORMATS` whitelist.
2. **HiveUtil.java** – Mark InputFormats containing `"lzo"` as
non-splittable (LZO files have no global index, cannot be split).
No BE changes needed: `LzopDecompressor` and `TextReader` already handle
`FORMAT_TEXT + LZOP`.
Co-authored-by: zhaorongsheng <[email protected]>
---
.../hive/scripts/auxlib/lzo-hadoop-1.0.6.tar.gz | Bin 0 -> 39584 bytes
.../scripts/create_preinstalled_scripts/run86.hql | 50 ++++++
.../preinstalled_data/text_lzo/part-m-00000.lzo | Bin 0 -> 201 bytes
.../text_lzo/part-m-00000.lzo.index | Bin 0 -> 8 bytes
.../doris/datasource/hive/HMSExternalTable.java | 12 ++
.../datasource/hive/HiveExternalMetaCache.java | 18 ++-
.../org/apache/doris/datasource/hive/HiveUtil.java | 36 ++++-
.../doris/nereids/rules/analysis/BindSink.java | 13 ++
.../doris/planner/BaseExternalTableDataSink.java | 12 ++
.../datasource/hive/HMSExternalTableTest.java | 114 ++++++++++++++
.../datasource/hive/HiveMetaStoreCacheTest.java | 87 ++++++++++
.../apache/doris/datasource/hive/HiveUtilTest.java | 175 +++++++++++++++++++++
.../hive/test_hive_lzo_text_format.out | 54 +++++++
.../hive/test_hive_lzo_text_format.groovy | 131 +++++++++++++++
14 files changed, 698 insertions(+), 4 deletions(-)
diff --git
a/docker/thirdparties/docker-compose/hive/scripts/auxlib/lzo-hadoop-1.0.6.tar.gz
b/docker/thirdparties/docker-compose/hive/scripts/auxlib/lzo-hadoop-1.0.6.tar.gz
new file mode 100644
index 00000000000..6c49c7ffe8f
Binary files /dev/null and
b/docker/thirdparties/docker-compose/hive/scripts/auxlib/lzo-hadoop-1.0.6.tar.gz
differ
diff --git
a/docker/thirdparties/docker-compose/hive/scripts/create_preinstalled_scripts/run86.hql
b/docker/thirdparties/docker-compose/hive/scripts/create_preinstalled_scripts/run86.hql
new file mode 100644
index 00000000000..a1d2766bb06
--- /dev/null
+++
b/docker/thirdparties/docker-compose/hive/scripts/create_preinstalled_scripts/run86.hql
@@ -0,0 +1,50 @@
+
+use `multi_catalog`;
+
+-- lzo-hadoop (org.anarres) mapreduce-API LZO text InputFormat
+-- Class is provided by auxlib/lzo-hadoop-1.0.6.jar (cp to /opt/hive/lib on
boot)
+CREATE TABLE text_lzo_format (
+ id INT,
+ value INT,
+ name STRING,
+ score DOUBLE,
+ dt DATE
+)
+ROW FORMAT DELIMITED
+FIELDS TERMINATED BY '\001'
+STORED AS
+ INPUTFORMAT 'com.hadoop.mapreduce.LzoTextInputFormat'
+ OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
+LOCATION '/user/doris/preinstalled_data/text_lzo';
+
+-- lzo-hadoop (org.anarres) legacy mapred-API wrapper, same file format
+CREATE TABLE text_deprecated_lzo_format (
+ id INT,
+ value INT,
+ name STRING,
+ score DOUBLE,
+ dt DATE
+)
+ROW FORMAT DELIMITED
+FIELDS TERMINATED BY '\001'
+STORED AS
+ INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'
+ OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
+LOCATION '/user/doris/preinstalled_data/text_lzo';
+
+-- Indexed LZO table: directory contains both part-m-00000.lzo (data) and
+-- part-m-00000.lzo.index (Hadoop-LZO sidecar). Doris must filter out the
+-- index file and only scan the .lzo data file.
+CREATE TABLE text_lzo_indexed_format (
+ id INT,
+ value INT,
+ name STRING,
+ score DOUBLE,
+ dt DATE
+)
+ROW FORMAT DELIMITED
+FIELDS TERMINATED BY '\001'
+STORED AS
+ INPUTFORMAT 'com.hadoop.mapreduce.LzoTextInputFormat'
+ OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
+LOCATION '/user/doris/preinstalled_data/text_lzo';
diff --git
a/docker/thirdparties/docker-compose/hive/scripts/preinstalled_data/text_lzo/part-m-00000.lzo
b/docker/thirdparties/docker-compose/hive/scripts/preinstalled_data/text_lzo/part-m-00000.lzo
new file mode 100644
index 00000000000..18591afdb5b
Binary files /dev/null and
b/docker/thirdparties/docker-compose/hive/scripts/preinstalled_data/text_lzo/part-m-00000.lzo
differ
diff --git
a/docker/thirdparties/docker-compose/hive/scripts/preinstalled_data/text_lzo/part-m-00000.lzo.index
b/docker/thirdparties/docker-compose/hive/scripts/preinstalled_data/text_lzo/part-m-00000.lzo.index
new file mode 100644
index 00000000000..c4a5886b57e
Binary files /dev/null and
b/docker/thirdparties/docker-compose/hive/scripts/preinstalled_data/text_lzo/part-m-00000.lzo.index
differ
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java
index 9865660978b..b9b9d5f8415 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HMSExternalTable.java
@@ -158,6 +158,18 @@ public class HMSExternalTable extends ExternalTable
implements MTMVRelatedTableI
// So add to SUPPORTED_HIVE_FILE_FORMATS and treat is as a hive table.
// Then Doris will just list the files from location and read parquet
files directly.
SUPPORTED_HIVE_FILE_FORMATS.add("org.apache.hudi.hadoop.HoodieParquetInputFormatBase");
+ // LZO compressed text formats (hadoop-lzo / lzo-hadoop), treat as
text input and use LZOP decompressor.
+ // LZO text InputFormats (read-only; INSERT INTO these tables is
explicitly blocked at planning time).
+ // All three class names contain "text", so HiveFileFormat.getFormat()
correctly resolves
+ // them to TEXT_FILE, which combined with LazySimpleSerDe yields
FORMAT_TEXT for reading.
+ // isSplittable() recognises all three via isLzoInputFormat() and
returns false.
+ // File listing filters *.lzo files only (*.lzo.index sidecars are
excluded).
+ // com.hadoop.compression.lzo.LzoTextInputFormat - twitter
hadoop-lzo (GPL)
+ // com.hadoop.mapreduce.LzoTextInputFormat - lzo-hadoop
mapreduce API (org.anarres)
+ // com.hadoop.mapred.DeprecatedLzoTextInputFormat - lzo-hadoop
legacy mapred API (org.anarres)
+
SUPPORTED_HIVE_FILE_FORMATS.add("com.hadoop.compression.lzo.LzoTextInputFormat");
+
SUPPORTED_HIVE_FILE_FORMATS.add("com.hadoop.mapreduce.LzoTextInputFormat");
+
SUPPORTED_HIVE_FILE_FORMATS.add("com.hadoop.mapred.DeprecatedLzoTextInputFormat");
SUPPORTED_HIVE_TRANSACTIONAL_FILE_FORMATS = Sets.newHashSet();
SUPPORTED_HIVE_TRANSACTIONAL_FILE_FORMATS.add("org.apache.hadoop.hive.ql.io.orc.OrcInputFormat");
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveExternalMetaCache.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveExternalMetaCache.java
index 02bcfacd06c..f3464deaea1 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveExternalMetaCache.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveExternalMetaCache.java
@@ -403,9 +403,16 @@ public class HiveExternalMetaCache extends
AbstractExternalMetaCache {
try {
RemoteIterator<FileEntry> iterator = directoryLister.listFiles(fs,
isRecursiveDirectories,
table, path.getNormalizedLocation());
+ boolean isLzoInputFormat = HiveUtil.isLzoInputFormat(inputFormat);
while (iterator.hasNext()) {
FileEntry entry = iterator.next();
String srcPath = entry.location().uri().toString();
+ // For LZO text InputFormats, only include *.lzo data files.
+ // *.lzo.index sidecar files and any other non-*.lzo files
must be excluded,
+ // mirroring the file filtering semantics of Hive's
LzoTextInputFormat.listStatus().
+ if (isLzoInputFormat && !HiveUtil.isLzoDataFile(srcPath)) {
+ continue;
+ }
LocationPath locationPath = LocationPath.of(srcPath,
path.getStorageProperties());
result.addFile(entry, locationPath);
}
@@ -651,7 +658,7 @@ public class HiveExternalMetaCache extends
AbstractExternalMetaCache {
}
fileEntry.invalidateKey(new FileCacheKey(nameMapping.getCtlId(),
tableId, partition.getPath(),
- null, partition.getPartitionValues()));
+ partition.getInputFormat(),
partition.getPartitionValues()));
partitionEntry.invalidateKey(partKey);
}
@@ -921,7 +928,11 @@ public class HiveExternalMetaCache extends
AbstractExternalMetaCache {
private long dummyKey = 0;
private long catalogId;
private String location;
- // Not part of cache identity.
+ // inputFormat is part of cache identity because the cached
FileCacheValue is
+ // format-dependent: isSplittable() and file-filtering (e.g. LZO
*.lzo.index
+ // exclusion) both depend on the InputFormat class name. Two Hive
tables that
+ // share the same partition location but declare different
InputFormats must
+ // therefore get independent cache entries.
private String inputFormat;
// The values of partitions.
protected List<String> partitionValues;
@@ -956,6 +967,7 @@ public class HiveExternalMetaCache extends
AbstractExternalMetaCache {
}
return catalogId == ((FileCacheKey) obj).catalogId
&& location.equals(((FileCacheKey) obj).location)
+ && Objects.equals(inputFormat, ((FileCacheKey)
obj).inputFormat)
&& Objects.equals(partitionValues, ((FileCacheKey)
obj).partitionValues);
}
@@ -968,7 +980,7 @@ public class HiveExternalMetaCache extends
AbstractExternalMetaCache {
if (dummyKey != 0) {
return Objects.hash(dummyKey);
}
- return Objects.hash(catalogId, location, partitionValues);
+ return Objects.hash(catalogId, location, inputFormat,
partitionValues);
}
@Override
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveUtil.java
index b99541c2bde..260e7e0f12f 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveUtil.java
@@ -111,10 +111,44 @@ public final class HiveUtil {
public static boolean isSplittable(FileSystem remoteFileSystem, String
inputFormat,
String location) throws UserException {
- // All supported hive input format are splittable
+ // LZO files are not splittable (unless .lzo.index exists, but Doris
does not support indexed split).
+ // Use contains("lzo") to cover LzoTextInputFormat,
DeprecatedLzoTextInputFormat, and future variants.
+ if (isLzoInputFormat(inputFormat)) {
+ return false;
+ }
+ // All other supported hive input formats are splittable
return
HMSExternalTable.SUPPORTED_HIVE_FILE_FORMATS.contains(inputFormat);
}
+ /**
+ * Returns true if the given InputFormat class name is one of the
hadoop-lzo text InputFormat variants.
+ * These formats only read *.lzo data files and must exclude *.lzo.index
sidecar files.
+ */
+ public static boolean isLzoInputFormat(String inputFormat) {
+ return inputFormat != null &&
inputFormat.toLowerCase().contains("lzo");
+ }
+
+ /**
+ * For LZO text InputFormats, only *.lzo files are data files.
+ * *.lzo.index and any other non-*.lzo files are sidecar/metadata files
that must be excluded.
+ * This mirrors the filtering semantics of Hive's
LzoTextInputFormat.listStatus().
+ *
+ * @param filePath the full path of the file entry
+ * @return true if the file should be included in the scan set for an LZO
InputFormat
+ */
+ public static boolean isLzoDataFile(String filePath) {
+ // Normalise: strip query-string/fragment if any
+ String path = filePath;
+ int q = path.indexOf('?');
+ if (q >= 0) {
+ path = path.substring(0, q);
+ }
+ // Only include files whose name ends with ".lzo"
+ // Files ending with ".lzo.index" or any other extension are excluded.
+ String lower = path.toLowerCase();
+ return lower.endsWith(".lzo");
+ }
+
// "c1=a/c2=b/c3=c" ---> List(["c1","a"], ["c2","b"], ["c3","c"])
// Similar to the `toPartitionValues` method, except that it adds the
partition column name.
public static List<String[]> toPartitionColNameAndValues(String
partitionName) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
index 36e8e0ebb9f..3dcdb471a11 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSink.java
@@ -38,6 +38,7 @@ import org.apache.doris.datasource.PluginDrivenExternalTable;
import org.apache.doris.datasource.doris.RemoteDorisExternalTable;
import org.apache.doris.datasource.hive.HMSExternalDatabase;
import org.apache.doris.datasource.hive.HMSExternalTable;
+import org.apache.doris.datasource.hive.HiveUtil;
import org.apache.doris.datasource.iceberg.IcebergExternalDatabase;
import org.apache.doris.datasource.iceberg.IcebergExternalTable;
import org.apache.doris.datasource.iceberg.IcebergUtils;
@@ -659,6 +660,18 @@ public class BindSink implements AnalysisRuleFactory {
throw new AnalysisException("Not support insert with partition
spec in hive catalog.");
}
+ // Fast-fail: if the table-level SD already declares an LZO
InputFormat, reject immediately
+ // without entering the expensive partition-lookup path in
bindDataSink().
+ // Note: this is a best-effort early check. The definitive LZO guard
lives in
+ // BaseExternalTableDataSink.getTFileFormatType(), which is called for
both the table-level
+ // SD and every existing partition SD — covering the case where the
table SD is plain text
+ // but individual partitions override it with an LZO InputFormat.
+ String inputFormat = table.getRemoteTable().getSd().getInputFormat();
+ if (HiveUtil.isLzoInputFormat(inputFormat)) {
+ throw new AnalysisException("INSERT INTO is not supported for LZO
Hive tables "
+ + "(input format: " + inputFormat + "). LZO tables are
read-only in Doris.");
+ }
+
List<Column> bindColumns;
if (sink.getColNames().isEmpty()) {
bindColumns =
table.getBaseSchema(true).stream().collect(ImmutableList.toImmutableList());
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/planner/BaseExternalTableDataSink.java
b/fe/fe-core/src/main/java/org/apache/doris/planner/BaseExternalTableDataSink.java
index 433162f93fe..8ebdf9d538e 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/planner/BaseExternalTableDataSink.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/planner/BaseExternalTableDataSink.java
@@ -23,6 +23,7 @@ package org.apache.doris.planner;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.FsBroker;
import org.apache.doris.common.AnalysisException;
+import org.apache.doris.datasource.hive.HiveUtil;
import
org.apache.doris.nereids.trees.plans.commands.insert.InsertCommandContext;
import org.apache.doris.thrift.TDataSink;
import org.apache.doris.thrift.TFileCompressType;
@@ -75,6 +76,17 @@ public abstract class BaseExternalTableDataSink extends
DataSink {
}
protected TFileFormatType getTFileFormatType(String format) throws
AnalysisException {
+ // LZO InputFormats must be rejected before any other match, because
their class names also
+ // contain "text" (e.g. LzoTextInputFormat) and would otherwise
silently match FORMAT_CSV_PLAIN.
+ // The BE writer has no LZO codec for Hive sink: it emits plain-text
files without a .lzo
+ // suffix, while the read path for LZO partitions filters to *.lzo
only — causing every
+ // Doris-written row to become permanently invisible. Reject here to
cover both the
+ // table-level SD (line ~126) and every existing partition SD (line
~223 in HiveTableSink),
+ // since both resolve their write format through this method.
+ if (HiveUtil.isLzoInputFormat(format)) {
+ throw new AnalysisException("INSERT INTO is not supported for LZO
Hive tables "
+ + "(input format: " + format + "). LZO tables are
read-only in Doris.");
+ }
TFileFormatType fileFormatType = TFileFormatType.FORMAT_UNKNOWN;
String lowerCase = format.toLowerCase();
if (lowerCase.contains("orc")) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HMSExternalTableTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HMSExternalTableTest.java
index a061aea5b8c..a3d61fd9753 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HMSExternalTableTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HMSExternalTableTest.java
@@ -17,6 +17,12 @@
package org.apache.doris.datasource.hive;
+import org.apache.doris.common.UserException;
+import org.apache.doris.thrift.TFileFormatType;
+
+import org.apache.hadoop.hive.metastore.api.SerDeInfo;
+import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
+import org.apache.hadoop.hive.metastore.api.Table;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -87,6 +93,114 @@ public class HMSExternalTableTest {
Assertions.assertEquals(TEST_VIEW_TEXT, table.getViewText());
}
+ //
-------------------------------------------------------------------------
+ // Tests for SUPPORTED_HIVE_FILE_FORMATS whitelist (LZO input formats)
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void
testSupportedFileFormats_ContainsCompressionLzoTextInputFormat() {
+ // twitter hadoop-lzo (GPL):
com.hadoop.compression.lzo.LzoTextInputFormat
+ Assertions.assertTrue(
+ HMSExternalTable.SUPPORTED_HIVE_FILE_FORMATS.contains(
+ "com.hadoop.compression.lzo.LzoTextInputFormat"),
+ "com.hadoop.compression.lzo.LzoTextInputFormat should be in
the supported formats whitelist");
+ }
+
+ @Test
+ public void testSupportedFileFormats_ContainsMapreduceLzoTextInputFormat()
{
+ // lzo-hadoop (org.anarres) mapreduce API:
com.hadoop.mapreduce.LzoTextInputFormat
+ Assertions.assertTrue(
+ HMSExternalTable.SUPPORTED_HIVE_FILE_FORMATS.contains(
+ "com.hadoop.mapreduce.LzoTextInputFormat"),
+ "com.hadoop.mapreduce.LzoTextInputFormat should be in the
supported formats whitelist");
+ }
+
+ @Test
+ public void
testSupportedFileFormats_ContainsDeprecatedLzoTextInputFormat() {
+ // lzo-hadoop (org.anarres) legacy mapred API:
com.hadoop.mapred.DeprecatedLzoTextInputFormat
+ Assertions.assertTrue(
+ HMSExternalTable.SUPPORTED_HIVE_FILE_FORMATS.contains(
+ "com.hadoop.mapred.DeprecatedLzoTextInputFormat"),
+ "com.hadoop.mapred.DeprecatedLzoTextInputFormat should be in
the supported formats whitelist");
+ }
+
+ //
-------------------------------------------------------------------------
+ // Tests for getFileFormatType: LZO tables must reject INSERT INTO
+ //
-------------------------------------------------------------------------
+
+ /**
+ * Build a minimal Hive Table SD stub with the given InputFormat class
name.
+ */
+ private Table buildRemoteTableWithInputFormat(String inputFormatName) {
+ SerDeInfo serDeInfo = new SerDeInfo();
+
serDeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
+ StorageDescriptor sd = new StorageDescriptor();
+ sd.setInputFormat(inputFormatName);
+ sd.setSerdeInfo(serDeInfo);
+ Table remoteTable = new Table();
+ remoteTable.setSd(sd);
+ return remoteTable;
+ }
+
+ @Test
+ public void testGetFileFormatType_LzoTextInputFormat_ReturnsText() throws
UserException {
+ // LZO tables use the LazySimpleSerDe (text SerDe);
getFileFormatType() must return
+ // FORMAT_TEXT so that the read path can decode the CSV-like payload
inside each .lzo block.
+ // The INSERT rejection lives in BindSink.bindHiveTableSink(), NOT
here.
+ String lzoFormat = "com.hadoop.compression.lzo.LzoTextInputFormat";
+ Table remoteTable = buildRemoteTableWithInputFormat(lzoFormat);
+ TestHMSExternalTableWithRemote lzoTable = new
TestHMSExternalTableWithRemote(
+ mockCatalog, mockDb, remoteTable);
+ TFileFormatType type = lzoTable.getFileFormatType(null);
+ Assertions.assertEquals(TFileFormatType.FORMAT_TEXT, type,
+ "LZO table with LazySimpleSerDe should resolve to FORMAT_TEXT
for reading");
+ }
+
+ @Test
+ public void
testGetFileFormatType_DeprecatedLzoTextInputFormat_ReturnsText() throws
UserException {
+ String lzoFormat = "com.hadoop.mapred.DeprecatedLzoTextInputFormat";
+ Table remoteTable = buildRemoteTableWithInputFormat(lzoFormat);
+ TestHMSExternalTableWithRemote lzoTable = new
TestHMSExternalTableWithRemote(
+ mockCatalog, mockDb, remoteTable);
+ TFileFormatType type = lzoTable.getFileFormatType(null);
+ Assertions.assertEquals(TFileFormatType.FORMAT_TEXT, type,
+ "DeprecatedLzoTextInputFormat table should also resolve to
FORMAT_TEXT for reading");
+ }
+
+ @Test
+ public void
testGetFileFormatType_MapreduceLzoTextInputFormat_ReturnsText() throws
UserException {
+ String lzoFormat = "com.hadoop.mapreduce.LzoTextInputFormat";
+ Table remoteTable = buildRemoteTableWithInputFormat(lzoFormat);
+ TestHMSExternalTableWithRemote lzoTable = new
TestHMSExternalTableWithRemote(
+ mockCatalog, mockDb, remoteTable);
+ TFileFormatType type = lzoTable.getFileFormatType(null);
+ Assertions.assertEquals(TFileFormatType.FORMAT_TEXT, type,
+ "com.hadoop.mapreduce.LzoTextInputFormat table should also
resolve to FORMAT_TEXT for reading");
+ }
+
+ /**
+ * Variant that exposes a pre-built remote table for getFileFormatType
tests.
+ */
+ private static class TestHMSExternalTableWithRemote extends
HMSExternalTable {
+ private final Table remoteTable;
+
+ public TestHMSExternalTableWithRemote(HMSExternalCatalog catalog,
+ HMSExternalDatabase db, Table remoteTable) {
+ super(1L, "test_table", "test_table", catalog, db);
+ this.remoteTable = remoteTable;
+ }
+
+ @Override
+ public Table getRemoteTable() {
+ return remoteTable;
+ }
+
+ @Override
+ protected synchronized void makeSureInitialized() {
+ this.objectCreated = true;
+ }
+ }
+
/**
* Test implementation of HMSExternalTable that allows setting view texts
* Uses parent's getViewText() implementation for actual testing
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveMetaStoreCacheTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveMetaStoreCacheTest.java
index 108a45e0372..04b5bdde1dc 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveMetaStoreCacheTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveMetaStoreCacheTest.java
@@ -114,4 +114,91 @@ public class HiveMetaStoreCacheTest {
entry.forEach((k, v) -> count.incrementAndGet());
return count.get();
}
+
+ //
-------------------------------------------------------------------------
+ // FileCacheKey identity: inputFormat must be part of equals() / hashCode()
+ // so that two tables at the same partition location but with different
+ // InputFormats (e.g. TextInputFormat vs LzoTextInputFormat) never share
+ // a cached FileCacheValue.
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void testFileCacheKeyIdentity_SameInputFormat_Equal() {
+ long catalogId = 1L;
+ long id = 100L;
+ String location = "hdfs://namenode/warehouse/db/tbl/dt=2024-01-01";
+ String inputFormat = "org.apache.hadoop.mapred.TextInputFormat";
+ ArrayList<String> partitionValues = new ArrayList<>();
+
+ HiveExternalMetaCache.FileCacheKey key1 = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location, inputFormat, partitionValues);
+ HiveExternalMetaCache.FileCacheKey key2 = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location, inputFormat, partitionValues);
+
+ Assertions.assertEquals(key1, key2,
+ "Keys with same catalogId, location, inputFormat and
partitionValues must be equal");
+ Assertions.assertEquals(key1.hashCode(), key2.hashCode(),
+ "Equal keys must have equal hashCodes");
+ }
+
+ @Test
+ public void testFileCacheKeyIdentity_DifferentInputFormat_NotEqual() {
+ long catalogId = 1L;
+ long id = 100L;
+ String location = "hdfs://namenode/warehouse/db/tbl/dt=2024-01-01";
+ ArrayList<String> partitionValues = new ArrayList<>();
+
+ // TextInputFormat table and LzoTextInputFormat table share the same
partition path.
+ // Without inputFormat in the cache identity they would collide and
one table could
+ // inherit the other's file list (e.g. TextInputFormat table inherits
filtered .lzo
+ // listing, or LZO table inherits an unfiltered, splittable listing).
+ HiveExternalMetaCache.FileCacheKey textKey = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location,
+ "org.apache.hadoop.mapred.TextInputFormat", partitionValues);
+ HiveExternalMetaCache.FileCacheKey lzoKey = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location,
+ "com.hadoop.mapreduce.LzoTextInputFormat", partitionValues);
+
+ Assertions.assertNotEquals(textKey, lzoKey,
+ "Keys with different inputFormats must NOT be equal even when
location is identical");
+ Assertions.assertNotEquals(textKey.hashCode(), lzoKey.hashCode(),
+ "Keys with different inputFormats should have different
hashCodes");
+ }
+
+ @Test
+ public void testFileCacheKeyIdentity_AllLzoVariants_Distinct() {
+ long catalogId = 1L;
+ long id = 100L;
+ String location = "hdfs://namenode/warehouse/db/tbl/dt=2024-01-01";
+ ArrayList<String> partitionValues = new ArrayList<>();
+
+ HiveExternalMetaCache.FileCacheKey lzoKey = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location,
"com.hadoop.compression.lzo.LzoTextInputFormat", partitionValues);
+ HiveExternalMetaCache.FileCacheKey lzoMrKey = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location,
"com.hadoop.mapreduce.LzoTextInputFormat", partitionValues);
+ HiveExternalMetaCache.FileCacheKey deprecatedLzoKey = new
HiveExternalMetaCache.FileCacheKey(
+ catalogId, id, location,
"com.hadoop.mapred.DeprecatedLzoTextInputFormat", partitionValues);
+
+ // All three LZO variants are distinct input formats and must produce
distinct cache keys.
+ Assertions.assertNotEquals(lzoKey, lzoMrKey);
+ Assertions.assertNotEquals(lzoKey, deprecatedLzoKey);
+ Assertions.assertNotEquals(lzoMrKey, deprecatedLzoKey);
+ }
+
+ @Test
+ public void testFileCacheKeyIdentity_DummyKey_IgnoresInputFormat() {
+ // Dummy keys are keyed by (catalogId, id) only; inputFormat must not
affect them.
+ long catalogId = 1L;
+ long id = 100L;
+ String location = "hdfs://namenode/warehouse/db/tbl";
+
+ HiveExternalMetaCache.FileCacheKey dummy1 =
HiveExternalMetaCache.FileCacheKey
+ .createDummyCacheKey(catalogId, id, location,
"org.apache.hadoop.mapred.TextInputFormat");
+ HiveExternalMetaCache.FileCacheKey dummy2 =
HiveExternalMetaCache.FileCacheKey
+ .createDummyCacheKey(catalogId, id, location,
"com.hadoop.mapreduce.LzoTextInputFormat");
+
+ Assertions.assertEquals(dummy1, dummy2,
+ "Dummy keys with same catalogId and id must be equal
regardless of inputFormat");
+ Assertions.assertEquals(dummy1.hashCode(), dummy2.hashCode());
+ }
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveUtilTest.java
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveUtilTest.java
new file mode 100644
index 00000000000..4abbbd10020
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/datasource/hive/HiveUtilTest.java
@@ -0,0 +1,175 @@
+// 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.doris.datasource.hive;
+
+import org.apache.doris.common.UserException;
+import org.apache.doris.filesystem.FileSystem;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+/**
+ * Unit tests for {@link HiveUtil}, focusing on isSplittable() behavior
+ * for LZO compressed text InputFormats.
+ */
+public class HiveUtilTest {
+
+ private static final FileSystem MOCK_FS = Mockito.mock(FileSystem.class);
+ private static final String DUMMY_LOCATION =
"hdfs://namenode/warehouse/test.lzo";
+
+ //
-------------------------------------------------------------------------
+ // LZO InputFormat variants: must NOT be splittable
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void testIsSplittable_CompressionLzoTextInputFormat_ReturnsFalse()
throws UserException {
+ // twitter hadoop-lzo: com.hadoop.compression.lzo.LzoTextInputFormat
+ // LZO files have no global index by default, so they cannot be split.
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+ "com.hadoop.compression.lzo.LzoTextInputFormat",
DUMMY_LOCATION);
+ Assertions.assertFalse(result,
+ "com.hadoop.compression.lzo.LzoTextInputFormat should not be
splittable");
+ }
+
+ @Test
+ public void testIsSplittable_MapreduceLzoTextInputFormat_ReturnsFalse()
throws UserException {
+ // lzo-hadoop (org.anarres) mapreduce API:
com.hadoop.mapreduce.LzoTextInputFormat
+ // LZO files have no global index by default, so they cannot be split.
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+ "com.hadoop.mapreduce.LzoTextInputFormat", DUMMY_LOCATION);
+ Assertions.assertFalse(result,
+ "com.hadoop.mapreduce.LzoTextInputFormat should not be
splittable");
+ }
+
+ @Test
+ public void testIsSplittable_DeprecatedLzoTextInputFormat_ReturnsFalse()
throws UserException {
+ // lzo-hadoop (org.anarres) legacy mapred API:
com.hadoop.mapred.DeprecatedLzoTextInputFormat
+ // It produces the same .lzo file format and is equally non-splittable.
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+ "com.hadoop.mapred.DeprecatedLzoTextInputFormat",
DUMMY_LOCATION);
+ Assertions.assertFalse(result,
+ "com.hadoop.mapred.DeprecatedLzoTextInputFormat should not be
splittable");
+ }
+
+ //
-------------------------------------------------------------------------
+ // Standard splittable formats: must still be splittable
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void testIsSplittable_TextInputFormat_ReturnsTrue() throws
UserException {
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+ "org.apache.hadoop.mapred.TextInputFormat", DUMMY_LOCATION);
+ Assertions.assertTrue(result,
+ "org.apache.hadoop.mapred.TextInputFormat should be
splittable");
+ }
+
+ @Test
+ public void testIsSplittable_ParquetInputFormat_ReturnsTrue() throws
UserException {
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+
"org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat",
DUMMY_LOCATION);
+ Assertions.assertTrue(result,
+ "MapredParquetInputFormat should be splittable");
+ }
+
+ @Test
+ public void testIsSplittable_OrcInputFormat_ReturnsTrue() throws
UserException {
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+ "org.apache.hadoop.hive.ql.io.orc.OrcInputFormat",
DUMMY_LOCATION);
+ Assertions.assertTrue(result,
+ "OrcInputFormat should be splittable");
+ }
+
+ //
-------------------------------------------------------------------------
+ // Unsupported format: must return false (not in whitelist)
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void testIsSplittable_UnsupportedFormat_ReturnsFalse() throws
UserException {
+ boolean result = HiveUtil.isSplittable(MOCK_FS,
+ "org.apache.hadoop.mapred.SequenceFileInputFormat",
DUMMY_LOCATION);
+ Assertions.assertFalse(result,
+ "Unsupported input format should not be splittable");
+ }
+
+ //
-------------------------------------------------------------------------
+ // isLzoInputFormat: class-name detection
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void testIsLzoInputFormat_CompressionVariant() {
+
Assertions.assertTrue(HiveUtil.isLzoInputFormat("com.hadoop.compression.lzo.LzoTextInputFormat"));
+ }
+
+ @Test
+ public void testIsLzoInputFormat_MapreduceVariant() {
+
Assertions.assertTrue(HiveUtil.isLzoInputFormat("com.hadoop.mapreduce.LzoTextInputFormat"));
+ }
+
+ @Test
+ public void testIsLzoInputFormat_DeprecatedVariant() {
+
Assertions.assertTrue(HiveUtil.isLzoInputFormat("com.hadoop.mapred.DeprecatedLzoTextInputFormat"));
+ }
+
+ @Test
+ public void testIsLzoInputFormat_NonLzo() {
+
Assertions.assertFalse(HiveUtil.isLzoInputFormat("org.apache.hadoop.mapred.TextInputFormat"));
+
Assertions.assertFalse(HiveUtil.isLzoInputFormat("org.apache.hadoop.hive.ql.io.orc.OrcInputFormat"));
+ }
+
+ @Test
+ public void testIsLzoInputFormat_Null_ReturnsFalse() {
+ // Null inputFormat (e.g. damaged HMS metadata) must not throw NPE;
treat as non-LZO.
+ Assertions.assertFalse(HiveUtil.isLzoInputFormat(null));
+ }
+
+ //
-------------------------------------------------------------------------
+ // isLzoDataFile: sidecar filter
+ //
-------------------------------------------------------------------------
+
+ @Test
+ public void testIsLzoDataFile_DataFile() {
+ // Real LZO data files must be included
+
Assertions.assertTrue(HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.lzo"));
+ Assertions.assertTrue(HiveUtil.isLzoDataFile("/data/part-00001.LZO"));
// case-insensitive
+ }
+
+ @Test
+ public void testIsLzoDataFile_IndexSidecar_Excluded() {
+ // .lzo.index sidecar files must be excluded
+
Assertions.assertFalse(HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.lzo.index"));
+
Assertions.assertFalse(HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.LZO.INDEX"));
+ }
+
+ @Test
+ public void testIsLzoDataFile_OtherExtensions_Excluded() {
+ // Other files in the partition directory must also be excluded for
LZO InputFormats
+
Assertions.assertFalse(HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000"));
+
Assertions.assertFalse(HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.gz"));
+
Assertions.assertFalse(HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.orc"));
+ }
+
+ @Test
+ public void testIsLzoDataFile_QueryStringStripped() {
+ // Paths with query strings should still be recognised correctly
+ Assertions.assertTrue(
+
HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.lzo?auth=token"));
+ Assertions.assertFalse(
+
HiveUtil.isLzoDataFile("hdfs://namenode/warehouse/part-m-00000.lzo.index?auth=token"));
+ }
+}
diff --git
a/regression-test/data/external_table_p0/hive/test_hive_lzo_text_format.out
b/regression-test/data/external_table_p0/hive/test_hive_lzo_text_format.out
new file mode 100644
index 00000000000..7659a2dfb82
--- /dev/null
+++ b/regression-test/data/external_table_p0/hive/test_hive_lzo_text_format.out
@@ -0,0 +1,54 @@
+-- This file is automatically generated. You should know what you did.
+
+-- !lzo_count --
+5
+
+-- !lzo_all --
+1 100 Alice 3.14 2024-01-01
+2 200 Bob 2.71 2024-01-02
+3 300 Carol 1.41 2024-01-03
+4 400 Dave 0.57 2024-01-04
+5 500 Eve 1.73 2024-01-05
+
+-- !lzo_filter --
+3 Carol
+4 Dave
+5 Eve
+
+-- !lzo_agg --
+1500 1.9120000000000001 2024-01-01 2024-01-05
+
+-- !deprecated_lzo_count --
+5
+
+-- !deprecated_lzo_all --
+1 100 Alice 3.14 2024-01-01
+2 200 Bob 2.71 2024-01-02
+3 300 Carol 1.41 2024-01-03
+4 400 Dave 0.57 2024-01-04
+5 500 Eve 1.73 2024-01-05
+
+-- !deprecated_lzo_filter --
+3 Carol
+4 Dave
+5 Eve
+
+-- !deprecated_lzo_agg --
+1500 1.9120000000000001 2024-01-01 2024-01-05
+
+-- !indexed_lzo_count --
+5
+
+-- !indexed_lzo_all --
+1 100 Alice 3.14 2024-01-01
+2 200 Bob 2.71 2024-01-02
+3 300 Carol 1.41 2024-01-03
+4 400 Dave 0.57 2024-01-04
+5 500 Eve 1.73 2024-01-05
+
+-- !indexed_vs_plain --
+5 5
+
+-- !cross_validate --
+5 5 5
+
diff --git
a/regression-test/suites/external_table_p0/hive/test_hive_lzo_text_format.groovy
b/regression-test/suites/external_table_p0/hive/test_hive_lzo_text_format.groovy
new file mode 100644
index 00000000000..c29dbd7ae9a
--- /dev/null
+++
b/regression-test/suites/external_table_p0/hive/test_hive_lzo_text_format.groovy
@@ -0,0 +1,131 @@
+
+// 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.
+
+suite("test_hive_lzo_text_format",
"p0,external,hive,external_docker,external_docker_hive") {
+ String enabled = context.config.otherConfigs.get("enableHiveTest")
+ if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+ logger.info("disable Hive test.")
+ return
+ }
+
+ for (String hivePrefix : ["hive3"]) {
+ String hmsPort = context.config.otherConfigs.get(hivePrefix +
"HmsPort")
+ String externalEnvIp =
context.config.otherConfigs.get("externalEnvIp")
+ String catalogName = "${hivePrefix}_test_hive_lzo_text_format"
+
+ sql """drop catalog if exists ${catalogName}"""
+ sql """
+ CREATE CATALOG ${catalogName} PROPERTIES (
+ 'type' = 'hms',
+ 'hive.metastore.uris' = 'thrift://${externalEnvIp}:${hmsPort}',
+ 'hadoop.username' = 'hive'
+ )
+ """
+
+ sql """use `${catalogName}`.`multi_catalog`"""
+
+ // ----------------------------------------------------------------
+ // 1. com.hadoop.mapreduce.LzoTextInputFormat (lzo-hadoop mapreduce
API)
+ // ----------------------------------------------------------------
+ order_qt_lzo_count """
+ select count(*) from text_lzo_format
+ """
+
+ order_qt_lzo_all """
+ select id, value, name, score, dt
+ from text_lzo_format
+ order by id
+ """
+
+ order_qt_lzo_filter """
+ select id, name
+ from text_lzo_format
+ where id > 2
+ order by id
+ """
+
+ order_qt_lzo_agg """
+ select sum(value), avg(score), min(dt), max(dt)
+ from text_lzo_format
+ """
+
+ // ----------------------------------------------------------------
+ // 2. com.hadoop.mapred.DeprecatedLzoTextInputFormat (lzo-hadoop
legacy mapred API)
+ // ----------------------------------------------------------------
+ order_qt_deprecated_lzo_count """
+ select count(*) from text_deprecated_lzo_format
+ """
+
+ order_qt_deprecated_lzo_all """
+ select id, value, name, score, dt
+ from text_deprecated_lzo_format
+ order by id
+ """
+
+ order_qt_deprecated_lzo_filter """
+ select id, name
+ from text_deprecated_lzo_format
+ where id > 2
+ order by id
+ """
+
+ order_qt_deprecated_lzo_agg """
+ select sum(value), avg(score), min(dt), max(dt)
+ from text_deprecated_lzo_format
+ """
+
+ // ----------------------------------------------------------------
+ // 3. com.hadoop.mapreduce.LzoTextInputFormat with .lzo.index sidecar
+ // The partition directory contains both:
+ // - part-m-00000.lzo (data file, must be scanned)
+ // - part-m-00000.lzo.index (Hadoop-LZO sidecar, must be excluded)
+ // Doris must filter out the index sidecar and return the same 5
rows.
+ // Without the fix, Doris would try to read the .lzo.index file as
+ // FORMAT_TEXT + PLAIN compression and return garbage or fail.
+ // ----------------------------------------------------------------
+ order_qt_indexed_lzo_count """
+ select count(*) from text_lzo_indexed_format
+ """
+
+ order_qt_indexed_lzo_all """
+ select id, value, name, score, dt
+ from text_lzo_indexed_format
+ order by id
+ """
+
+ // Key assertion: result must be identical to the non-indexed table.
+ // If .lzo.index were incorrectly scanned, count() would be 6 (or
fail).
+ order_qt_indexed_vs_plain """
+ select
+ (select count(*) from text_lzo_format) as plain_cnt,
+ (select count(*) from text_lzo_indexed_format) as indexed_cnt
+ """
+
+ // ----------------------------------------------------------------
+ // 4. Cross-validate: all three tables must return identical row counts
+ // ----------------------------------------------------------------
+ order_qt_cross_validate """
+ select
+ (select count(*) from text_lzo_format) as lzo_cnt,
+ (select count(*) from text_deprecated_lzo_format) as
deprecated_lzo_cnt,
+ (select count(*) from text_lzo_indexed_format) as
indexed_lzo_cnt
+ """
+
+ sql """drop catalog if exists ${catalogName}"""
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]