Skip to content

Commit 7c16296

Browse files
committed
fix: Avoid WriteKind duplication between connector and logical plan
Acutally I think it will be better to logical plan depends on connector, but it is as it is
1 parent 15cc39f commit 7c16296

File tree

13 files changed

+94
-113
lines changed

13 files changed

+94
-113
lines changed

axiom/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
add_library(axiom_common Session.cpp)
15+
add_library(axiom_common Session.cpp WriteKind.cpp)
1616

1717
target_link_libraries(axiom_common axiom_connectors)

axiom/common/WriteKind.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "axiom/common/WriteKind.h"
2+
3+
namespace facebook::axiom {
4+
namespace {
5+
6+
const auto& writeKindNames() {
7+
static const folly::F14FastMap<WriteKind, std::string_view> kNames = {
8+
{WriteKind::kCreate, "CREATE"},
9+
{WriteKind::kInsert, "INSERT"},
10+
{WriteKind::kUpdate, "UPDATE"},
11+
{WriteKind::kDelete, "DELETE"},
12+
};
13+
return kNames;
14+
}
15+
16+
} // namespace
17+
18+
AXIOM_DEFINE_ENUM_NAME(WriteKind, writeKindNames);
19+
20+
} // namespace facebook::axiom

axiom/common/WriteKind.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and its affiliates.
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+
#pragma once
17+
18+
#include "axiom/common/Enums.h"
19+
20+
namespace facebook::axiom {
21+
22+
/// Specifies what type of write is intended when initiating or concluding a
23+
/// write operation.
24+
enum class WriteKind {
25+
/// A write operation to a new table which does not yet exist in the
26+
/// connector. Covers both creation of an empty table and create as select
27+
/// operations.
28+
kCreate = 1,
29+
30+
/// Rows are added and all columns must be specified for the TableWriter.
31+
/// Covers insert, Hive partition replacement or any other operation which
32+
/// adds whole rows.
33+
kInsert = 2,
34+
35+
/// Individual rows are deleted. Only row ids as per
36+
/// ConnectorMetadata::rowIdHandles() are passed to the TableWriter.
37+
kDelete = 3,
38+
39+
/// Column values in individual rows are changed. The TableWriter
40+
/// gets first the row ids as per ConnectorMetadata::rowIdHandles()
41+
/// and then new values for the columns being changed. The new values
42+
/// may overlap with row ids if the row id is a set of primary key
43+
/// columns.
44+
kUpdate = 4,
45+
};
46+
47+
AXIOM_DECLARE_ENUM_NAME(WriteKind);
48+
49+
} // namespace facebook::axiom
50+
51+
AXIOM_ENUM_FORMATTER(facebook::axiom::WriteKind);

axiom/connectors/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ endif()
2626

2727
add_library(axiom_connectors ConnectorMetadata.cpp SchemaResolver.cpp SchemaUtils.cpp)
2828

29-
target_link_libraries(axiom_connectors velox_common_base velox_memory velox_connector)
29+
target_link_libraries(axiom_connectors axiom_common velox_common_base velox_memory velox_connector)

axiom/connectors/ConnectorMetadata.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include "axiom/connectors/ConnectorMetadata.h"
1818

1919
namespace facebook::axiom::connector {
20-
2120
namespace {
21+
2222
const auto& tableKindNames() {
2323
static const folly::F14FastMap<TableKind, std::string_view> kNames = {
2424
{TableKind::kTable, "TABLE"},
@@ -27,22 +27,10 @@ const auto& tableKindNames() {
2727
return kNames;
2828
}
2929

30-
const auto& writeKindNames() {
31-
static const folly::F14FastMap<WriteKind, std::string_view> kNames = {
32-
{WriteKind::kCreate, "CREATE"},
33-
{WriteKind::kInsert, "INSERT"},
34-
{WriteKind::kUpdate, "UPDATE"},
35-
{WriteKind::kDelete, "DELETE"},
36-
};
37-
return kNames;
38-
}
39-
4030
} // namespace
4131

4232
AXIOM_DEFINE_ENUM_NAME(TableKind, tableKindNames);
4333

44-
AXIOM_DEFINE_ENUM_NAME(WriteKind, writeKindNames);
45-
4634
namespace {
4735
velox::RowTypePtr makeRowType(const std::vector<const Column*>& columns) {
4836
folly::F14FastSet<std::string> uniqueNames;

axiom/connectors/ConnectorMetadata.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma once
1717

1818
#include "axiom/common/Enums.h"
19+
#include "axiom/common/WriteKind.h"
1920
#include "axiom/connectors/ConnectorSession.h"
2021
#include "axiom/connectors/ConnectorSplitManager.h"
2122
#include "velox/common/memory/HashStringAllocator.h"
@@ -480,33 +481,6 @@ class ConnectorWriteHandle {
480481

481482
using ConnectorWriteHandlePtr = std::shared_ptr<ConnectorWriteHandle>;
482483

483-
/// Specifies what type of write is intended when initiating or concluding a
484-
/// write operation.
485-
enum class WriteKind {
486-
/// A write operation to a new table which does not yet exist in the
487-
/// connector. Covers both creation of an empty table and create as select
488-
/// operations.
489-
kCreate = 1,
490-
491-
/// Rows are added and all columns must be specified for the TableWriter.
492-
/// Covers insert, Hive partition replacement or any other operation which
493-
/// adds whole rows.
494-
kInsert = 2,
495-
496-
/// Individual rows are deleted. Only row ids as per
497-
/// ConnectorMetadata::rowIdHandles() are passed to the TableWriter.
498-
kDelete = 3,
499-
500-
/// Column values in individual rows are changed. The TableWriter
501-
/// gets first the row ids as per ConnectorMetadata::rowIdHandles()
502-
/// and then new values for the columns being changed. The new values
503-
/// may overlap with row ids if the row id is a set of primary key
504-
/// columns.
505-
kUpdate = 4,
506-
};
507-
508-
AXIOM_DECLARE_ENUM_NAME(WriteKind);
509-
510484
using RowsFuture = folly::SemiFuture<int64_t>;
511485

512486
class ConnectorMetadata {
@@ -668,5 +642,3 @@ class ConnectorMetadata {
668642
} // namespace facebook::axiom::connector
669643

670644
AXIOM_ENUM_FORMATTER(facebook::axiom::connector::TableKind);
671-
672-
AXIOM_ENUM_FORMATTER(facebook::axiom::connector::WriteKind);

axiom/logical_plan/LogicalPlanNode.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,4 @@ void TableWriteNode::accept(
390390
visitor.visit(*this, context);
391391
}
392392

393-
namespace {
394-
395-
folly::F14FastMap<WriteKind, std::string_view> writeKindNames() {
396-
static const folly::F14FastMap<WriteKind, std::string_view> kNames = {
397-
{WriteKind::kCreate, "CREATE"},
398-
{WriteKind::kInsert, "INSERT"},
399-
{WriteKind::kUpdate, "UPDATE"},
400-
{WriteKind::kDelete, "DELETE"},
401-
};
402-
403-
return kNames;
404-
}
405-
406-
} // namespace
407-
408-
VELOX_DEFINE_ENUM_NAME(WriteKind, writeKindNames);
409-
410393
} // namespace facebook::axiom::logical_plan

axiom/logical_plan/LogicalPlanNode.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma once
1717

1818
#include "axiom/common/Enums.h"
19+
#include "axiom/common/WriteKind.h"
1920
#include "axiom/logical_plan/Expr.h"
2021
#include "velox/type/Variant.h"
2122
#include "velox/vector/ComplexVector.h"
@@ -659,32 +660,6 @@ class UnnestNode : public LogicalPlanNode {
659660

660661
using UnnestNodePtr = std::shared_ptr<const UnnestNode>;
661662

662-
/// Specifies what type of write is intended when initiating or concluding a
663-
/// write operation.
664-
enum class WriteKind {
665-
// A write operation to a new table which does not yet exist in the connector.
666-
// Covers both creation of an empty table and create as select operations.
667-
kCreate = 1,
668-
669-
// Rows are added and all columns must be specified for the TableWriter.
670-
// Covers insert, Hive partition replacement or any other operation which adds
671-
// whole rows.
672-
kInsert = 2,
673-
674-
// Individual rows are deleted. Only row ids as per
675-
// ConnectorMetadata::rowIdHandles() are passed to the TableWriter.
676-
kDelete = 3,
677-
678-
// Column values in individual rows are changed. The TableWriter
679-
// gets first the row ids as per ConnectorMetadata::rowIdHandles()
680-
// and then new values for the columns being changed. The new values
681-
// may overlap with row ids if the row id is a set of primary key
682-
// columns.
683-
kUpdate = 4,
684-
};
685-
686-
AXIOM_DECLARE_ENUM_NAME(WriteKind);
687-
688663
/// Implements create/insert/delete/update as per 'writeKind'.
689664
///
690665
/// The output schema contains a single BIGINT column named 'rows'. The value of
@@ -756,5 +731,3 @@ class TableWriteNode : public LogicalPlanNode {
756731
using TableWriteNodePtr = std::shared_ptr<const TableWriteNode>;
757732

758733
} // namespace facebook::axiom::logical_plan
759-
760-
AXIOM_ENUM_FORMATTER(facebook::axiom::logical_plan::WriteKind);

axiom/optimizer/QueryGraph.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ class WritePlan : public PlanObject {
939939
/// @param columnExprs Expressions producing the values to write.
940940
WritePlan(
941941
const connector::Table& table,
942-
connector::WriteKind kind,
942+
WriteKind kind,
943943
ExprVector columnExprs)
944944
: PlanObject{PlanType::kWriteNode},
945945
table_{table},
@@ -952,7 +952,7 @@ class WritePlan : public PlanObject {
952952
return table_;
953953
}
954954

955-
connector::WriteKind kind() const {
955+
WriteKind kind() const {
956956
return kind_;
957957
}
958958

@@ -962,7 +962,7 @@ class WritePlan : public PlanObject {
962962

963963
private:
964964
const connector::Table& table_;
965-
const connector::WriteKind kind_;
965+
const WriteKind kind_;
966966
const ExprVector columnExprs_;
967967
};
968968

axiom/optimizer/ToGraph.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,10 +1496,8 @@ PlanObjectP ToGraph::addLimit(const lp::LimitNode& limitNode) {
14961496
}
14971497

14981498
PlanObjectP ToGraph::addWrite(const lp::TableWriteNode& tableWrite) {
1499-
const auto writeKind =
1500-
static_cast<connector::WriteKind>(tableWrite.writeKind());
1501-
if (writeKind != connector::WriteKind::kInsert &&
1502-
writeKind != connector::WriteKind::kCreate) {
1499+
const auto writeKind = tableWrite.writeKind();
1500+
if (writeKind != WriteKind::kInsert && writeKind != WriteKind::kCreate) {
15031501
VELOX_NYI("Only INSERT supported for TableWrite");
15041502
}
15051503
VELOX_CHECK_NULL(

0 commit comments

Comments
 (0)