CharlieYan24 commented on code in PR #4459: URL: https://github.com/apache/linkis/pull/4459#discussion_r1168098690
########## linkis-commons/linkis-storage/src/main/java/org/apache/linkis/storage/resultset/StorageResultSetWriter.java: ########## @@ -0,0 +1,261 @@ +/* + * 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.linkis.storage.resultset; + +import org.apache.linkis.common.io.*; +import org.apache.linkis.common.io.resultset.*; +import org.apache.linkis.common.io.resultset.ResultSetWriter; +import org.apache.linkis.common.utils.*; +import org.apache.linkis.storage.*; +import org.apache.linkis.storage.conf.*; +import org.apache.linkis.storage.domain.*; +import org.apache.linkis.storage.utils.*; + +import org.apache.commons.io.IOUtils; +import org.apache.hadoop.hdfs.client.HdfsDataOutputStream; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StorageResultSetWriter<K extends MetaData, V extends Record> + extends ResultSetWriter<K, V> { + private static final Logger logger = LoggerFactory.getLogger(StorageResultSetWriter.class); + + private final ResultSet<K, V> resultSet; + private final long maxCacheSize; + private final FsPath storePath; + + private final ResultSerializer serializer; + private boolean moveToWriteRow = false; + private OutputStream outputStream = null; + private int rowCount = 0; + private final List<Byte> buffer = new ArrayList<Byte>(); + private Fs fs = null; + private MetaData rMetaData = null; + private String proxyUser = StorageUtils.getJvmUser(); + private boolean fileCreated = false; + private boolean closed = false; + private final Object WRITER_LOCK_CREATE = new Object(); + private final Object WRITER_LOCK_CLOSE = new Object(); + + public StorageResultSetWriter(ResultSet<K, V> resultSet, long maxCacheSize, FsPath storePath) { + super(resultSet, maxCacheSize, storePath); + this.resultSet = resultSet; + this.maxCacheSize = maxCacheSize; + this.storePath = storePath; + + this.serializer = resultSet.createResultSetSerializer(); + } + + public MetaData getMetaData() { + return rMetaData; + } + + public void setProxyUser(String proxyUser) { + this.proxyUser = proxyUser; + } + + public boolean isEmpty() { + return rMetaData == null && buffer.size() <= Dolphin.FILE_EMPTY; + } + + public void init() { + try { + writeLine(resultSet.getResultSetHeader(), true); + } catch (IOException e) { + logger.warn("StorageResultSetWriter init failed", e); + } + } + + public void createNewFile() { + if (!fileCreated) { + synchronized (WRITER_LOCK_CREATE) { + if (!fileCreated) { + if (storePath != null && outputStream == null) { + logger.info( + String.format( + "Try to create a new file:%s, with proxy user:%s", storePath, proxyUser)); + fs = FSFactory.getFsByProxyUser(storePath, proxyUser); + try { + fs.init(null); + FileSystemUtils.createNewFile(storePath, proxyUser, true); + outputStream = fs.write(storePath, true); + } catch (IOException e) { + } + logger.info(String.format("Succeed to create a new file:%s", storePath)); Review Comment: Already use logger's string template to replace String.format() -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@linkis.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@linkis.apache.org For additional commands, e-mail: notifications-h...@linkis.apache.org