-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ksql-connect): introduce syntax for CREATE CONNECTOR (syntax onl…
…y) (#3139)
- Loading branch information
Showing
5 changed files
with
215 additions
and
5 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
98 changes: 98 additions & 0 deletions
98
ksql-parser/src/main/java/io/confluent/ksql/parser/tree/CreateConnector.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,98 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.parser.tree; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import jdk.nashorn.internal.ir.annotations.Immutable; | ||
|
||
@Immutable | ||
public class CreateConnector extends Statement { | ||
|
||
public enum Type { | ||
SOURCE, | ||
SINK | ||
} | ||
|
||
private final String name; | ||
private final ImmutableMap<String, Literal> config; | ||
private final Type type; | ||
|
||
public CreateConnector( | ||
final Optional<NodeLocation> location, | ||
final String name, | ||
final Map<String, Literal> config, | ||
final Type type | ||
) { | ||
super(location); | ||
this.name = Objects.requireNonNull(name, "name"); | ||
this.config = ImmutableMap.copyOf(Objects.requireNonNull(config, "config")); | ||
this.type = Objects.requireNonNull(type, "type"); | ||
} | ||
|
||
public CreateConnector( | ||
final String name, | ||
final Map<String, Literal> config, | ||
final Type type | ||
) { | ||
this(Optional.empty(), name, config, type); | ||
} | ||
|
||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Map<String, Literal> getConfig() { | ||
return config; | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
final CreateConnector that = (CreateConnector) o; | ||
return Objects.equals(name, that.name) | ||
&& Objects.equals(config, that.config) | ||
&& Objects.equals(type, that.type); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, config, type); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CreateConnector{" | ||
+ "name='" + name + '\'' | ||
+ ", config=" + config | ||
+ ", type=" + type | ||
+ '}'; | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
ksql-parser/src/test/java/io/confluent/ksql/parser/tree/CreateConnectorTest.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,55 @@ | ||
/* | ||
* Copyright 2019 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.parser.tree; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.testing.EqualsTester; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.junit.Test; | ||
|
||
public class CreateConnectorTest { | ||
|
||
private static final NodeLocation SOME_LOCATION = new NodeLocation(0, 0); | ||
private static final NodeLocation OTHER_LOCATION = new NodeLocation(1, 0); | ||
|
||
private static final String NAME = "foo"; | ||
private static final String OTHER_NAME = "bar"; | ||
|
||
private static final Map<String, Literal> CONFIG = ImmutableMap.of("foo", new StringLiteral("bar")); | ||
private static final Map<String, Literal> OTHER_CONFIG = ImmutableMap.of("foo", new StringLiteral("baz")); | ||
|
||
@Test | ||
public void testEquals() { | ||
new EqualsTester() | ||
.addEqualityGroup( | ||
new CreateConnector(Optional.of(SOME_LOCATION), NAME, CONFIG, CreateConnector.Type.SOURCE), | ||
new CreateConnector(Optional.of(OTHER_LOCATION), NAME, CONFIG, CreateConnector.Type.SOURCE), | ||
new CreateConnector(NAME, CONFIG, CreateConnector.Type.SOURCE) | ||
) | ||
.addEqualityGroup( | ||
new CreateConnector(OTHER_NAME, CONFIG, CreateConnector.Type.SOURCE) | ||
) | ||
.addEqualityGroup( | ||
new CreateConnector(NAME, OTHER_CONFIG, CreateConnector.Type.SOURCE) | ||
) | ||
.addEqualityGroup( | ||
new CreateConnector(NAME, CONFIG, CreateConnector.Type.SINK) | ||
) | ||
.testEquals(); | ||
} | ||
|
||
} |