Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import com.clougence.clouddm.sdk.analysis.column.QueryConstraintService;
import com.clougence.clouddm.sdk.service.approval.ApprovalRefreshService;
import com.clougence.clouddm.sdk.service.cache.CacheService;
import com.clougence.clouddm.sdk.service.config.ConfigService;
import com.clougence.clouddm.sdk.service.config.ConsoleConfigService;
import com.clougence.clouddm.sdk.service.execute.MetaService;
import com.clougence.clouddm.sdk.service.execute.SessionService;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -46,10 +48,15 @@ public class DmConsolePluginLoader {
private MetaService metaService;
@Resource
private QueryConstraintService queryConstraintService;
@Resource
private SessionService sessionServices;
@Resource
private ConfigService pluginConfigService;

public void loadPlugin(ClassLoader parentClassLoader) throws Exception {
this.cacheService.init();
//PluginManager.putService(SessionService.class, this.sessionServices);
PluginManager.putService(SessionService.class, this.sessionServices);
PluginManager.putService(ConfigService.class, this.pluginConfigService);
PluginManager.putService(CacheService.class, this.cacheService);
PluginManager.putService(MetaService.class, this.metaService);
PluginManager.putService(QueryConstraintService.class, this.queryConstraintService);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2026 杭州开云集致科技有限公司
*
* Licensed 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.
*/

plugins {
id 'com.clougence.java-conventions'
}

dependencies {
api project(':cg-utils')
api project(':cgdm-plugin-sdk')
}

description = 'cg-com-results-file'
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
* 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 com.clougence.clouddm.worker.component.result;
*/
package com.clougence.clouddm.component.resultfile;

import com.clougence.clouddm.sdk.execute.resultset.file.ResultType;

public interface EntityType {

/** see: StorageCode */
/** see: StorageCode */
byte Code = ResultType.Code; // (byte) 0x00;
byte Boolean = ResultType.Boolean; // (byte) 0x01;
byte Byte = ResultType.Byte; // (byte) 0x02;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* 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 com.clougence.clouddm.worker.component.result;
*/
package com.clougence.clouddm.component.resultfile;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* 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 com.clougence.clouddm.worker.component.result;
*/
package com.clougence.clouddm.component.resultfile;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* 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 com.clougence.clouddm.worker.component.result;
*/
package com.clougence.clouddm.component.resultfile;

public interface ResultDataTag {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,35 @@
* 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 com.clougence.clouddm.worker.services;
*/
package com.clougence.clouddm.component.resultfile;

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.*;

import com.clougence.clouddm.api.common.GlobalConfUtils;
import com.clougence.clouddm.base.metadata.ds.ColMetaData;
import com.clougence.clouddm.sdk.execute.resultset.echo.ResultSetValue;
import com.clougence.clouddm.sdk.execute.resultset.file.ResultReader;
import com.clougence.clouddm.sdk.execute.resultset.file.ResultSetFileCode;
import com.clougence.clouddm.sdk.execute.session.QueryRequest;
import com.clougence.clouddm.sdk.execute.session.QueryResultConf;
import com.clougence.clouddm.sdk.execute.session.result.ReaderOptions;
import com.clougence.clouddm.sdk.execute.resultset.file.ResultReader;
import com.clougence.clouddm.sdk.execute.resultset.file.ResultSetFileCode;
import com.clougence.clouddm.sdk.execute.resultset.echo.ResultSetValue;
import com.clougence.clouddm.worker.component.result.EntityType;
import com.clougence.clouddm.worker.component.result.FileResultSetInputStream;
import com.clougence.clouddm.worker.component.result.ResultDataTag;
import com.clougence.clouddm.worker.component.result.ResultSetInputStream.DataHeader;
import com.clougence.clouddm.worker.component.result.ResultSetInputStream.RowHeader;
import com.clougence.clouddm.worker.component.session.storage.RowDataHelper;
import com.clougence.utils.HexadecimalUtils;
import com.clougence.utils.JsonUtils;
import com.clougence.utils.io.IOUtils;
import com.clougence.clouddm.component.resultfile.ResultSetInputStream.DataHeader;
import com.clougence.clouddm.component.resultfile.ResultSetInputStream.RowHeader;

class SidecarResultReaderImpl implements ResultReader {
public class ResultFileReader implements ResultReader {

private final FileResultSetInputStream resultInput;
private final QueryRequest queryRequest;
private final ColMetaData[] colMetaData;
private final ReaderOptions options;

public SidecarResultReaderImpl(File resultFile) throws IOException{
public ResultFileReader(File resultFile) throws IOException{
this.resultInput = new FileResultSetInputStream(resultFile);

this.resultInput.nextRow();
Expand All @@ -59,7 +55,7 @@ public SidecarResultReaderImpl(File resultFile) throws IOException{
this.options = new ReaderOptions();
this.options.setColumnBytesLimit(this.queryRequest.getResultConf().getFetchColumnBytesLimit());
this.options.setElementBytesLimit(this.queryRequest.getResultConf().getFetchElementBytesLimit());
this.options.setTempPath(GlobalConfUtils.getTempDataHome());
this.options.setTempPath(System.getProperty("java.io.tmpdir"));
this.options.setDataFormat(this.queryRequest.getResultConf().getDataFormat());
this.options.setTimeFormat(this.queryRequest.getResultConf().getTimeFormat());
this.options.setDataTimeFormat(this.queryRequest.getResultConf().getDataTimeFormat());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2026 杭州开云集致科技有限公司
*
* Licensed 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 com.clougence.clouddm.component.resultfile;

import java.io.File;
import java.io.IOException;

import com.clougence.clouddm.sdk.execute.resultset.file.ResultReader;
import com.clougence.clouddm.sdk.execute.resultset.file.ResultReaderService;

public class ResultFileReaderService implements ResultReaderService {

@Override
public ResultReader openReader(File resultFile) throws IOException {
if (resultFile == null) {
throw new NullPointerException("resultFile is null");
}
if (!resultFile.exists() || !resultFile.isFile()) {
throw new IOException("resultFile not exists or not file:" + resultFile.getAbsolutePath());
}

return new ResultFileReader(resultFile.getAbsoluteFile());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2026 杭州开云集致科技有限公司
*
* Licensed 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 com.clougence.clouddm.component.resultfile;

import java.sql.JDBCType;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

import com.clougence.clouddm.base.metadata.ds.ColMetaData;
import com.clougence.clouddm.sdk.execute.resultset.echo.ReceiveMode;
import com.clougence.clouddm.sdk.execute.session.QueryRequest;
import com.clougence.clouddm.sdk.execute.session.QueryResultConf;
import com.clougence.utils.StringUtils;
import com.clougence.utils.format.WellKnowFormat;

import lombok.Getter;

public class ResultFileRequests {

public static ResultFileRequest fromColumns(String queryBody, LinkedHashMap<String, JDBCType> columns) {
return fromColumns(null, queryBody, columns, null);
}

public static ResultFileRequest fromColumns(String queryBody, LinkedHashMap<String, JDBCType> columns, Map<String, String> variables) {
return fromColumns(null, queryBody, columns, variables);
}

public static ResultFileRequest fromColumns(String queryId, String queryBody, LinkedHashMap<String, JDBCType> columns, Map<String, String> variables) {
if (columns == null || columns.isEmpty()) {
throw new IllegalArgumentException("Result columns must not be empty.");
}

QueryRequest query = new QueryRequest();
query.setQueryId(StringUtils.isBlank(queryId) ? UUID.randomUUID().toString() : queryId);
query.setQueryBody(queryBody);
query.setRequestTime(new Date());
query.setVariables(variables == null ? new LinkedHashMap<>() : new LinkedHashMap<>(variables));
query.setResultConf(defaultResultConf());

ColMetaData[] metaData = new ColMetaData[columns.size()];
int index = 0;
for (Map.Entry<String, JDBCType> entry : columns.entrySet()) {
String column = entry.getKey();
if (StringUtils.isBlank(column)) {
throw new IllegalArgumentException("Result column name must not be blank.");
}

JDBCType jdbcType = entry.getValue() == null ? JDBCType.VARCHAR : entry.getValue();
ColMetaData meta = new ColMetaData();
meta.setColumn(column);
meta.setIndex(index + 1);
meta.setJdbcType(jdbcType);
meta.setColumnType(jdbcType.getName());
metaData[index++] = meta;
}

return new ResultFileRequest(query, metaData);
}

private static QueryResultConf defaultResultConf() {
QueryResultConf conf = new QueryResultConf();
conf.setReceiveMode(ReceiveMode.PAGINATED);
conf.setDisplayChars(Integer.MAX_VALUE);
conf.setDataFormat(WellKnowFormat.WKF_DATE10);
conf.setTimeFormat(WellKnowFormat.WKF_TIME24_S9);
conf.setDataTimeFormat(WellKnowFormat.WKF_DATE_TIME24_S9);
conf.setTimeWithZoneFormat(WellKnowFormat.WKF_OFFSET_TIME24_S9);
conf.setDataTimeWithZoneFormat(WellKnowFormat.WKF_OFFSET_DATE_TIME24_S9);
return conf;
}

@Getter
public static class ResultFileRequest {

private final QueryRequest query;
private final ColMetaData[] columns;

private ResultFileRequest(QueryRequest query, ColMetaData[] columns){
this.query = query;
this.columns = columns;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2026 杭州开云集致科技有限公司
*
* Licensed 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 com.clougence.clouddm.component.resultfile;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.List;

import com.clougence.clouddm.base.metadata.ds.ColMetaData;
import com.clougence.clouddm.sdk.execute.session.QueryRequest;
import com.clougence.utils.JsonUtils;

public class ResultFileWriter implements Closeable {

private final ResultSetOutputStream output;
private final int columnCount;

public static ResultFileWriter open(File file, QueryRequest query, ColMetaData[] columns) throws IOException {
return open(file, query, columns, Long.MAX_VALUE, Long.MAX_VALUE);
}

public static ResultFileWriter open(File file, QueryRequest query, ColMetaData[] columns, long fileLimit, long columnLimit) throws IOException {
if (file == null) {
throw new NullPointerException("file is null");
}
if (query == null) {
throw new NullPointerException("query is null");
}
if (columns == null || columns.length == 0) {
throw new IllegalArgumentException("columns must not be empty.");
}

ResultSetOutputStream output = new FileResultSetOutputStream(file.getAbsoluteFile(), false, ByteOrder.BIG_ENDIAN, fileLimit, columnLimit);
return new ResultFileWriter(output, query, columns);
}

public ResultFileWriter(ResultSetOutputStream output, QueryRequest query, ColMetaData[] columns) throws IOException{
this.output = output;
this.columnCount = columns.length;
this.writeMetadata(query, columns);
}

private void writeMetadata(QueryRequest query, ColMetaData[] columns) throws IOException {
this.output.newRow();
this.output.writeString((byte) 0, JsonUtils.toJson(query), StandardCharsets.UTF_8);
this.output.closeRow();

this.output.newRow();
for (ColMetaData column : columns) {
this.output.writeString((byte) 0, JsonUtils.toJson(column), StandardCharsets.UTF_8);
}
this.output.closeRow();
}

public void writeRow(List<String> values) throws IOException {
if (values == null) {
throw new NullPointerException("values is null");
}
if (values.size() != this.columnCount) {
throw new IllegalArgumentException("values size " + values.size() + " does not match column count " + this.columnCount + ".");
}

this.output.newRow();
for (String value : values) {
this.output.writeString((byte) 0, value, StandardCharsets.UTF_8);
}
this.output.closeRow();
}

@Override
public void close() throws IOException {
this.output.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* 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 com.clougence.clouddm.worker.component.result;
*/
package com.clougence.clouddm.component.resultfile;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Loading