|
| 1 | +/* |
| 2 | + * Copyright 2018- The Pixie Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + */ |
| 18 | + |
| 19 | +#include <fstream> |
| 20 | +#include <iostream> |
| 21 | +#include <string> |
| 22 | + |
| 23 | +#include "src/stirling/stirling.h" |
| 24 | +#include "src/table_store/schema/schema.h" |
| 25 | + |
| 26 | +DEFINE_string(out_file_path, "schema.pb", "The file to save the serialized Schema"); |
| 27 | + |
| 28 | +int main(int argc, char** argv) { |
| 29 | + px::EnvironmentGuard env_guard(&argc, argv); |
| 30 | + |
| 31 | + auto source_registry = px::stirling::CreateProdSourceRegistry(); |
| 32 | + auto sources = source_registry->sources(); |
| 33 | + |
| 34 | + absl::flat_hash_map<std::string, px::table_store::schema::Relation> rel_map; |
| 35 | + for (const auto& reg_element : sources) { |
| 36 | + for (auto schema : reg_element.schema) { |
| 37 | + px::table_store::schema::Relation relation; |
| 38 | + for (const auto& element : schema.elements()) { |
| 39 | + relation.AddColumn(element.type(), std::string(element.name()), element.stype(), |
| 40 | + element.desc()); |
| 41 | + } |
| 42 | + rel_map[schema.name()] = relation; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + px::table_store::schemapb::Schema schema_pb; |
| 47 | + PX_CHECK_OK(px::table_store::schema::Schema::ToProto(&schema_pb, rel_map)); |
| 48 | + |
| 49 | + std::ofstream out_schema; |
| 50 | + out_schema.open(FLAGS_out_file_path); |
| 51 | + schema_pb.SerializeToOstream(&out_schema); |
| 52 | + out_schema.close(); |
| 53 | + |
| 54 | + return 0; |
| 55 | +} |
0 commit comments