apache/dolphinscheduler · error · UnsupportedOperationException

K8S AdHocDataSourceClient is not supported

Error message

K8S AdHocDataSourceClient is not supported

What it means

K8sDataSourceChannel declares that the K8s datasource only supports pooled clients; createAdHocDataSourceClient unconditionally throws UnsupportedOperationException. Any code path requesting an ad-hoc (non-pooled) K8s datasource client will fail by design.

Source

Thrown at dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-k8s/src/main/java/org/apache/dolphinscheduler/plugin/datasource/k8s/K8sDataSourceChannel.java:30

 * 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.dolphinscheduler.plugin.datasource.k8s;

import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient;
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam;
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel;
import org.apache.dolphinscheduler.spi.datasource.PooledDataSourceClient;
import org.apache.dolphinscheduler.spi.enums.DbType;

public class K8sDataSourceChannel implements DataSourceChannel {

    @Override
    public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
        throw new UnsupportedOperationException("K8S AdHocDataSourceClient is not supported");
    }

    @Override
    public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) {
        throw new UnsupportedOperationException("K8S AdHocDataSourceClient is not supported");
    }
}

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Do not use the K8s datasource for ad-hoc SQL execution; use a JDBC datasource (e.g. MySQL/Postgres) for SQL tasks
  2. Use the K8s datasource only with task types that consume its pooled client / config path (e.g. K8s-related tasks)
  3. If ad-hoc support is required, implement createAdHocDataSourceClient in the plugin

Example fix

// before: assigning K8s datasource to a SQL task node
sqlTask.datasource = k8sDatasource // throws UnsupportedOperationException
// after
sqlTask.datasource = mysqlDatasource // use a JDBC-capable datasource
Defensive patterns

Strategy: validation

Validate before calling

if (dbType == DbType.K8S || "K8S".equals(datasource.getType())) {
  throw new IllegalArgumentException("K8s datasource does not support ad-hoc SQL execution; use a JDBC datasource");
}

Type guard

boolean supportsAdHoc(DbType t) { return t != DbType.K8S; }

Try / catch

try {
  client = channel.createAdHocDataSourceClient(connParam, dbType);
} catch (UnsupportedOperationException e) {
  if (e.getMessage().contains("K8S")) { client = fallbackJdbcClient(connParam); }
  else throw e;
}

Prevention

When it happens

Trigger: Calling createAdHocDataSourceClient on a K8s datasource channel — e.g. UI/API flows that execute ad-hoc SQL tasks against a K8s-type datasource.

Common situations: Using a K8s datasource for a task type that needs an ad-hoc JDBC connection (SQL task, ad-hoc query) instead of the K8s-specific task types the plugin supports.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/0a21542ca460fd73. Report an issue: GitHub.