Skip to content

fix(postgresql): resolve boolean = integer operator error across all … - #4584

Open
huge86 wants to merge 1 commit into
DataLinkDC:devfrom
huge86:fix/postgresql-boolean-integer
Open

huge86 wants to merge 1 commit into
DataLinkDC:devfrom
huge86:fix/postgresql-boolean-integer

Conversation

@huge86

@huge86 huge86 commented Oct 13, 2026

Copy link
Copy Markdown

Related Issue

Problem

When using PostgreSQL as Dinky's metadata database, the application fails to start with:

ERROR: operator does not exist: boolean = integer
LINE 1: SELECT ... FROM dinky_task WHERE enabled = 1
                                               ^^^^

Root Cause

Dinky defines enabled and other logical columns with different types per database:

Database Column Type Code Comparison Result
MySQL TINYINT(1) WHERE enabled = 1 ✅ Works
H2 TINYINT(1) WHERE enabled = 1 ✅ Works
PostgreSQL BOOLEAN WHERE enabled = 1 ❌ ERROR

PostgreSQL has no implicit BOOLEAN↔INTEGER conversion operator. The same issue affects auto_registers, is_leaf, is_delete, and other boolean columns.

This issue is not limited to enabled. A full codebase audit found 5 boolean fields using integer literals across 11 files.

Fix Applied

Change boolean field comparisons from integer literals to SQL-compliant boolean literals:

// Before  (PostgreSQL: BOOLEAN = INTEGER → ERROR)
.eq(field, 1)
.eq(field, 0)

// After   (PostgreSQL: BOOLEAN = TRUE/FALSE → OK)
.eq(field, true)
.eq(field, false)
<!-- Before -->
WHERE enabled = 1

<!-- After -->
WHERE enabled = true

Fields Changed (18 changes across 11 files)

Field Column Type (PostgreSQL) Java Entity Files
enabled BOOLEAN (baseline or V20241205-migrated) SuperEntity (inherited) AlertGroupServiceImpl, AlertInstanceServiceImpl, ClusterInstanceServiceImpl, DataBaseServiceImpl, DocumentServiceImpl (×2), FragmentVariableServiceImpl, TaskServiceImpl (×3)
enabled BOOLEAN (same as above) N/A (XML) AlertRulesMapper.xml, ClusterInstanceMapper.xml, TaskMapper.xml (×2)
autoRegisters BOOLEAN (baseline) ClusterInstance ClusterInstanceServiceImpl
isLeaf BOOLEAN (baseline) Catalogue TaskServiceImpl
isDelete BOOLEAN (baseline) Tenant TenantServiceImpl

Fields Intentionally NOT Changed

Field PostgreSQL Type Reason
tenantAdminFlag (UserTenant) SMALLINT (never migrated) Would produce SMALLINT = TRUE which PostgreSQL also rejects. Kept as 1.
ProTableUtil.is_delete SMALLINT Static string literal "is_delete", not a Java boolean field. Unrelated pattern.

Backward Compatibility

Fully backward-compatible with MySQL and H2 (Dinky's other officially-supported metadata databases):

Database Column Type col = 1 (old) col = true (new)
MySQL TINYINT(1) ✅ Direct match ✅ MySQL converts TRUE → 1 internally
H2 TINYINT(1) ✅ Direct match ✅ H2 same behavior as MySQL
PostgreSQL BOOLEAN ❌ ERROR ✅ Standard SQL boolean comparison

Why this is safe for MySQL/H2: Both databases treat TRUE as the integer 1 internally. WHERE enabled = true produces identical query execution plans to WHERE enabled = 1.

Database Support Scope

Dinky officially supports 3 metadata databases (confirmed via dinky-admin/pom.xml and db/migration/ directories):

  • ✅ MySQL — application-mysql.yml + db/migration/mysql/ + mysql-connector-java
  • ✅ PostgreSQL — application-postgresql.yml + db/migration/postgresql/ + postgresql driver
  • ✅ H2 — application-h2.yml + db/migration/h2/ + h2 driver
  • ❌ Oracle/SQL Server/SQLite/达梦/人大金仓 — not supported as Dinky metadata DB (no profile, no migration, no driver in dinky-admin/pom.xml). dinky-metadata-oracle/sqlserver are Flink Catalog Connectors (for querying external data sources from Flink SQL), not Dinky's own metadata database.

Verification

  • PostgreSQL baseline confirmed: All 5 changed fields are BOOLEAN (verified via V20240506.1.0.2__baseline.sql column definitions)
  • PostgreSQL V20241205 migration confirmed: enabled columns on alert_* and fragment tables already migrated from SMALLINT → BOOLEAN via backup-table-and-rename pattern
  • SMALLINT guard: UserTenant.tenantAdminFlag correctly excluded (PostgreSQL SMALLINT, no BOOLEAN migration)
  • MySQL/H2 column types: All changed fields are TINYINT(1), which accepts boolean literals
  • PostgreSQL official docs: Confirmed BOOLEAN = INTEGER operator does not exist (https://www.postgresql.org/docs/current/datatype-boolean.html)
  • Issue [Bug] Database postgresql adaptation problem #4262 correlation: Multiple users across pg12.7/pg13.6/pg15.7 reported same operator does not exist: boolean = integer error
  • No new bugs introduced: Only literal value changes (1→true, 0→false), no logic alterations, no new imports, no structural changes

Change Summary

11 files changed, 18 insertions(+), 18 deletions(-)

Java ServiceImpl:
  AlertGroupServiceImpl.java         - 1 change
  AlertInstanceServiceImpl.java      - 1 change
  ClusterInstanceServiceImpl.java    - 3 changes (enabled ×2 + autoRegisters ×1)
  DataBaseServiceImpl.java           - 1 change
  DocumentServiceImpl.java           - 2 changes
  FragmentVariableServiceImpl.java   - 1 change
  TaskServiceImpl.java               - 4 changes (enabled ×3 + isLeaf ×1)
  TenantServiceImpl.java             - 1 change

XML Mapper:
  AlertRulesMapper.xml               - 1 change
  ClusterInstanceMapper.xml          - 1 change
  TaskMapper.xml                     - 2 changes

…boolean fields

PostgreSQL does not support implicit conversion between BOOLEAN and INTEGER:
  ERROR: operator does not exist: boolean = integer

Changed all boolean field comparisons from integer literals to SQL-compliant
boolean literals (true/false) for fields that are BOOLEAN in PostgreSQL:

  SuperEntity.enabled       → BOOLEAN (baseline)          9 files
  ClusterInstance.autoRegisters → BOOLEAN (baseline)       1 file
  Catalogue.isLeaf          → BOOLEAN (baseline)          1 file
  Tenant.isDelete           → BOOLEAN (baseline)          1 file

Columns migrated by V20241205 SMALLINT→BOOLEAN:
  dinky_alert_instance.enabled, dinky_alert_group.enabled,
  dinky_alert_rules.enabled, dinky_fragment.enabled

NOT changed (both MySQL and PostgreSQL keep SMALLINT/TINYINT):
  UserTenant.tenantAdminFlag → kept as 1, not BOOLEAN anywhere

MySQL backwards-compatible: MySQL treats TRUE as 1 internally.

Fixes upstream issue DataLinkDC#4262

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant