Skip to content

Commit d8cac61

Browse files
committed
add comments for interfaces
1 parent 082044a commit d8cac61

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/copyto/CopyToOptions.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,68 @@
3030
import java.util.List;
3131
import java.util.Set;
3232

33+
/**
34+
* Interface for COPY TO command options.
35+
*
36+
* <p>This interface defines the configuration for COPY TO operations, including target format,
37+
* target table name, column mappings, and memory management. Implementations provide
38+
* format-specific validation and inference logic.
39+
*/
3340
public interface CopyToOptions extends Accountable {
3441

42+
/**
43+
* Infers and validates options based on query analysis and relation plan.
44+
*
45+
* <p>This method is called during analysis phase to fill in default values and validate
46+
* user-specified options against the query structure. For example, it can infer the target time
47+
* column from the query's time column if not explicitly specified.
48+
*
49+
* @param analysis the query analysis containing metadata about the query
50+
* @param queryRelationPlan the logical relation plan of the inner query
51+
* @param columnHeaders the column headers from the query result
52+
*/
3553
void infer(Analysis analysis, RelationPlan queryRelationPlan, List<ColumnHeader> columnHeaders);
3654

55+
/**
56+
* Validates the options against the actual column schema.
57+
*
58+
* <p>This method is called after planning to ensure the specified options (e.g., target columns,
59+
* tags) are valid for the given output schema.
60+
*
61+
* @param columnHeaders the column headers of the query result
62+
* @throws SemanticException if validation fails
63+
*/
3764
void check(List<ColumnHeader> columnHeaders);
3865

66+
/**
67+
* Returns the response column headers for the result set.
68+
*
69+
* <p>These headers describe the columns that will be returned to the client after the COPY TO
70+
* operation completes (e.g., file path, row count).
71+
*
72+
* @return list of column headers for the response
73+
*/
3974
List<ColumnHeader> getRespColumnHeaders();
4075

76+
/**
77+
* Returns the target output format.
78+
*
79+
* @return the format enum value
80+
*/
4181
Format getFormat();
4282

83+
/**
84+
* Estimates the maximum memory usage in bytes required for writing.
85+
*
86+
* <p>This is used for memory management and determining whether to flush data to disk.
87+
*
88+
* @return estimated maximum memory usage in bytes
89+
*/
4390
long estimatedMaxRamBytesInWrite();
4491

92+
/** Supported output formats for COPY TO command. */
4593
enum Format {
94+
/** TsFile format output. */
4695
TSFILE,
4796
}
4897

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/copyto/IFormatCopyToWriter.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,50 @@
2323

2424
import java.io.IOException;
2525

26+
/**
27+
* Interface for writing query results to external storage formats.
28+
*
29+
* <p>This interface abstracts the writing logic so that different output formats (e.g., TsFile,
30+
* CSV) can be supported. Each implementation handles format-specific operations like encoding,
31+
* schema definition, and file sealing.
32+
*/
2633
public interface IFormatCopyToWriter {
34+
35+
/**
36+
* Writes a TsBlock containing query results to the target storage.
37+
*
38+
* @param tsBlock the data block to write, containing rows of query results
39+
* @throws Exception if write fails (e.g., IO error, encoding error)
40+
*/
2741
void write(TsBlock tsBlock) throws Exception;
2842

43+
/**
44+
* Builds a TsBlock containing metadata or summary information about the written data.
45+
*
46+
* <p>This is typically called after all data has been written to return information about the
47+
* output, such as file paths, row counts, or statistics.
48+
*
49+
* @return a TsBlock containing result metadata, or null if no result is needed
50+
*/
2951
TsBlock buildResultTsBlock();
3052

53+
/**
54+
* Finalizes the writing process and prepares the file for reading.
55+
*
56+
* <p>This method ensures all data is flushed to disk and necessary footer/headers are written.
57+
* After seal() is called, no more data should be written.
58+
*
59+
* @throws Exception if sealing fails
60+
*/
3161
void seal() throws Exception;
3262

63+
/**
64+
* Closes the writer and releases all resources.
65+
*
66+
* <p>This method should be called after seal() to ensure proper cleanup of file handles, buffers,
67+
* and other resources.
68+
*
69+
* @throws IOException if close fails
70+
*/
3371
void close() throws IOException;
3472
}

0 commit comments

Comments
 (0)