Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: set column type priority (#18054)

Lynn7ac59d1a3694
diff --git a/rag/app/table.py b/rag/app/table.py
index 7c7cbd1431..114f62dd58 100644
--- a/rag/app/table.py
+++ b/rag/app/table.py
@@ -392,7 +392,7 @@ def column_data_type(arr):
if int(s) > 2**63 - 1:
float_flag = True
break
- elif re.match(r"[+-]?[0-9.]{,19}$", s.replace("%%", "")) and not s.replace("%%", "").startswith("0"):
+ elif re.match(r"[+-]?[0-9]+\.[0-9]*$", s.replace("%%", "")) and not s.replace("%%", "").startswith("0"):
counts["float"] += 1
elif re.match(r"(true|yes|是|\*|✓|✔|☑|✅|√|false|no|否|⍻|×)$", s, flags=re.IGNORECASE):
counts["bool"] += 1
@@ -403,7 +403,10 @@ def column_data_type(arr):
if float_flag:
ty = "float"
else:
- counts = sorted(counts.items(), key=lambda x: x[1] * -1)
+ # When counts tie, prefer types that lose less data:
+ # text (lossless) > datetime > float > int > bool
+ type_priority = {"text": 0, "datetime": 1, "float": 2, "int": 3, "bool": 4}
+ counts = sorted(counts.items(), key=lambda x: (x[1] * -1, type_priority[x[0]]))
ty = counts[0][0]
for i in range(len(arr)):
if arr[i] is None: