-
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.
refactor: type safety for column, source and function name strings (#…
- Loading branch information
Showing
262 changed files
with
2,904 additions
and
2,642 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
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
44 changes: 44 additions & 0 deletions
44
ksql-common/src/main/java/io/confluent/ksql/name/ColumnName.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,44 @@ | ||
/* | ||
* 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.name; | ||
|
||
import com.google.errorprone.annotations.Immutable; | ||
|
||
/** | ||
* The name of a column within a source. | ||
*/ | ||
@Immutable | ||
public final class ColumnName extends Name<ColumnName> { | ||
|
||
private static final String AGGREGATE_COLUMN_PREFIX = "KSQL_AGG_VARIABLE_"; | ||
|
||
public static ColumnName aggregate(final int idx) { | ||
return of(AGGREGATE_COLUMN_PREFIX + idx); | ||
} | ||
|
||
public static ColumnName of(final String name) { | ||
return new ColumnName(name); | ||
} | ||
|
||
private ColumnName(final String name) { | ||
super(name); | ||
} | ||
|
||
public boolean isAggregate() { | ||
return name.startsWith(AGGREGATE_COLUMN_PREFIX); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
ksql-common/src/main/java/io/confluent/ksql/name/FunctionName.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,33 @@ | ||
/* | ||
* 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.name; | ||
|
||
import com.google.errorprone.annotations.Immutable; | ||
|
||
/** | ||
* The name for a function (UDF or UDAF). | ||
*/ | ||
@Immutable | ||
public final class FunctionName extends Name<FunctionName> { | ||
|
||
public static FunctionName of(final String name) { | ||
return new FunctionName(name); | ||
} | ||
|
||
private FunctionName(final String name) { | ||
super(name); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
ksql-common/src/main/java/io/confluent/ksql/name/Name.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,96 @@ | ||
/* | ||
* 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.name; | ||
|
||
import com.google.errorprone.annotations.Immutable; | ||
import io.confluent.ksql.schema.ksql.FormatOptions; | ||
import io.confluent.ksql.util.Identifiers; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The base type for all names, which just wraps a String in | ||
* a type-safe wrapper and supplies formatting options. | ||
* | ||
* @param <T> ensure type safety of methods | ||
*/ | ||
@Immutable | ||
public abstract class Name<T extends Name<?>> { | ||
|
||
protected final String name; | ||
|
||
protected Name(final String name) { | ||
this.name = Identifiers.ensureTrimmed(Objects.requireNonNull(name, "name"), "name"); | ||
} | ||
|
||
// we should remove this getter after all code has | ||
// migrated to use Name instead of Strings to make | ||
// sure that we never lose type safety | ||
public String name() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @see String#equalsIgnoreCase(String) | ||
*/ | ||
public boolean equalsIgnoreCase(final T o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
return name.equalsIgnoreCase(o.name()); | ||
} | ||
|
||
public boolean startsWith(final T o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
return name.startsWith(o.name()); | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final Name<?> that = (Name<?>) o; | ||
return Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getClass(), name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toString(FormatOptions.none()); | ||
} | ||
|
||
public String toString(final FormatOptions formatOptions) { | ||
return formatOptions.escape(name); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
ksql-common/src/main/java/io/confluent/ksql/name/SourceName.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,34 @@ | ||
/* | ||
* 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.name; | ||
|
||
import com.google.errorprone.annotations.Immutable; | ||
|
||
/** | ||
* The name of a source (stream or table). | ||
*/ | ||
@Immutable | ||
public final class SourceName extends Name<SourceName> { | ||
|
||
public static SourceName of(final String name) { | ||
return new SourceName(name); | ||
} | ||
|
||
private SourceName(final String name) { | ||
super(name); | ||
} | ||
|
||
} |
Oops, something went wrong.