-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_file.cpp
More file actions
57 lines (50 loc) · 1.77 KB
/
merge_file.cpp
File metadata and controls
57 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Stryke
//
// https://github.com/edmBernard/Stryke
//
// Created by Erwan BERNARD on 22/12/2018.
//
// Copyright (c) 2018 Erwan BERNARD. All rights reserved.
// Distributed under the Apache License, Version 2.0. (See accompanying
// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0)
//
#include "date/date.h"
#include "stryke/core.hpp"
#include "stryke/reader.hpp"
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <regex>
#include <string>
namespace fs = std::filesystem;
int main(int argc, char const *argv[]) {
if (argc != 3) {
std::cout << "Usage: stryke_merge_file <sourcefolder> <outputfilename>\n"
<< "Merge file from a folder <sourcefolder> into one file <outputfilename>.\n"
<< "Output column name in the outputfile will be : 'timestamp','col1','col2','col3','col4'\n";
return 1;
}
try {
uint64_t count = 0;
auto writer = stryke::OrcWriterImpl<stryke::TimestampNumber, stryke::Long, stryke::Long, stryke::Long, stryke::Long>({"timestamp","col1","col2","col3","col4"}, argv[2], stryke::WriterOptions());
for (auto &p : fs::directory_iterator(argv[1])) {
if (p.is_regular_file()) {
if (std::regex_match(p.path().string(), std::regex(".*\\.orc"))) {
auto reader = stryke::OrcReader<stryke::TimestampNumber, stryke::Long, stryke::Long, stryke::Long, stryke::Long>(p.path().string());
auto result = reader.get_data();
for (auto &&i : result) {
++count;
writer.write_tuple(i);
}
}
}
}
std::cout << count << " lines merged in : " << argv[2] << std::endl;
} catch (std::exception &ex) {
std::cerr << "Caught exception: " << ex.what() << "\n";
return 1;
}
return 0;
}