forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-13118][jdbc] Introduce JDBC table factory and bridge JDBC tabl…
…e source with streaming table source (apache#9029)
- Loading branch information
Showing
15 changed files
with
1,122 additions
and
33 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
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
146 changes: 146 additions & 0 deletions
146
...onnectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCReadOptions.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,146 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.api.java.io.jdbc; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Options for the JDBC scan. | ||
*/ | ||
public class JDBCReadOptions implements Serializable { | ||
|
||
private final String partitionColumnName; | ||
private final Long partitionLowerBound; | ||
private final Long partitionUpperBound; | ||
private final Integer numPartitions; | ||
|
||
private final int fetchSize; | ||
|
||
private JDBCReadOptions( | ||
String partitionColumnName, | ||
Long partitionLowerBound, | ||
Long partitionUpperBound, | ||
Integer numPartitions, | ||
int fetchSize) { | ||
this.partitionColumnName = partitionColumnName; | ||
this.partitionLowerBound = partitionLowerBound; | ||
this.partitionUpperBound = partitionUpperBound; | ||
this.numPartitions = numPartitions; | ||
|
||
this.fetchSize = fetchSize; | ||
} | ||
|
||
public Optional<String> getPartitionColumnName() { | ||
return Optional.ofNullable(partitionColumnName); | ||
} | ||
|
||
public Optional<Long> getPartitionLowerBound() { | ||
return Optional.ofNullable(partitionLowerBound); | ||
} | ||
|
||
public Optional<Long> getPartitionUpperBound() { | ||
return Optional.ofNullable(partitionUpperBound); | ||
} | ||
|
||
public Optional<Integer> getNumPartitions() { | ||
return Optional.ofNullable(numPartitions); | ||
} | ||
|
||
public int getFetchSize() { | ||
return fetchSize; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof JDBCReadOptions) { | ||
JDBCReadOptions options = (JDBCReadOptions) o; | ||
return Objects.equals(partitionColumnName, options.partitionColumnName) && | ||
Objects.equals(partitionLowerBound, options.partitionLowerBound) && | ||
Objects.equals(partitionUpperBound, options.partitionUpperBound) && | ||
Objects.equals(numPartitions, options.numPartitions) && | ||
Objects.equals(fetchSize, options.fetchSize); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Builder of {@link JDBCReadOptions}. | ||
*/ | ||
public static class Builder { | ||
private String partitionColumnName; | ||
private Long partitionLowerBound; | ||
private Long partitionUpperBound; | ||
private Integer numPartitions; | ||
|
||
private int fetchSize = 0; | ||
|
||
/** | ||
* optional, name of the column used for partitioning the input. | ||
*/ | ||
public Builder setPartitionColumnName(String partitionColumnName) { | ||
this.partitionColumnName = partitionColumnName; | ||
return this; | ||
} | ||
|
||
/** | ||
* optional, the smallest value of the first partition. | ||
*/ | ||
public Builder setPartitionLowerBound(long partitionLowerBound) { | ||
this.partitionLowerBound = partitionLowerBound; | ||
return this; | ||
} | ||
|
||
/** | ||
* optional, the largest value of the last partition. | ||
*/ | ||
public Builder setPartitionUpperBound(long partitionUpperBound) { | ||
this.partitionUpperBound = partitionUpperBound; | ||
return this; | ||
} | ||
|
||
/** | ||
* optional, the maximum number of partitions that can be used for parallelism in table reading. | ||
*/ | ||
public Builder setNumPartitions(int numPartitions) { | ||
this.numPartitions = numPartitions; | ||
return this; | ||
} | ||
|
||
/** | ||
* optional, the number of rows to fetch per round trip. | ||
* default value is 0, according to the jdbc api, 0 means that fetchSize hint will be ignored. | ||
*/ | ||
public Builder setFetchSize(int fetchSize) { | ||
this.fetchSize = fetchSize; | ||
return this; | ||
} | ||
|
||
public JDBCReadOptions build() { | ||
return new JDBCReadOptions( | ||
partitionColumnName, partitionLowerBound, partitionUpperBound, numPartitions, fetchSize); | ||
} | ||
} | ||
} |
Oops, something went wrong.