forked from qiaojialin/tsfile-spark-connector
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7284637
commit f8d2572
Showing
15 changed files
with
241 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/cn/edu/thu/tsfile/io/TsFileOutputFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cn.edu.thu.tsfile.io; | ||
|
||
import cn.edu.thu.tsfile.timeseries.write.exception.WriteProcessException; | ||
import cn.edu.thu.tsfile.timeseries.write.record.TSRecord; | ||
import cn.edu.thu.tsfile.timeseries.write.schema.FileSchema; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.io.NullWritable; | ||
import org.apache.hadoop.mapreduce.RecordWriter; | ||
import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; | ||
import java.io.IOException; | ||
|
||
public class TsFileOutputFormat extends FileOutputFormat<NullWritable, TSRecord> { | ||
|
||
private FileSchema fileSchema; | ||
|
||
public TsFileOutputFormat(FileSchema fileSchema) { | ||
this.fileSchema = fileSchema; | ||
} | ||
|
||
@Override | ||
public RecordWriter<NullWritable, TSRecord> getRecordWriter(TaskAttemptContext job) | ||
throws IOException, InterruptedException { | ||
Path path = getDefaultWorkFile(job, ""); | ||
try { | ||
return new TsFileRecordWriter(job, path, fileSchema); | ||
} catch (WriteProcessException e) { | ||
e.printStackTrace(); | ||
throw new InterruptedException("construct TsFileRecordWriter failed"); | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/cn/edu/thu/tsfile/io/TsFileRecordWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cn.edu.thu.tsfile.io; | ||
|
||
import cn.edu.thu.tsfile.timeseries.FileFormat.TsFile; | ||
import cn.edu.thu.tsfile.timeseries.write.exception.WriteProcessException; | ||
import cn.edu.thu.tsfile.timeseries.write.record.TSRecord; | ||
import cn.edu.thu.tsfile.timeseries.write.schema.FileSchema; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.io.NullWritable; | ||
import org.apache.hadoop.mapreduce.RecordWriter; | ||
import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
|
||
import java.io.IOException; | ||
|
||
public class TsFileRecordWriter extends RecordWriter<NullWritable, TSRecord> { | ||
|
||
private TsFile tsFile = null; | ||
|
||
public TsFileRecordWriter(TaskAttemptContext job, Path file, FileSchema fileSchema) throws IOException, WriteProcessException { | ||
HDFSOutputStream hdfsOutputStream = new HDFSOutputStream(file.toString(), job.getConfiguration(), false); | ||
tsFile = new TsFile(hdfsOutputStream, fileSchema); | ||
} | ||
|
||
@Override | ||
public void close(TaskAttemptContext context) throws IOException { | ||
tsFile.close(); | ||
} | ||
|
||
@Override | ||
public synchronized void write(NullWritable arg0, TSRecord tsRecord) throws IOException { | ||
try { | ||
tsFile.writeLine(tsRecord); | ||
} catch (WriteProcessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.