Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add table name length limit for ingestion
Signed-off-by: Terence Lim <terencelimxp@gmail.com>
  • Loading branch information
terryyylim committed May 6, 2021
commit cf5f293a5f25b8cd10496b1651bc72032c60839e
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.apache.spark.sql.functions.{col, length, struct, udf}
import org.apache.spark.sql.{DataFrame, Row, SQLContext}
import org.apache.spark.sql.sources.{BaseRelation, InsertableRelation}
import org.apache.spark.sql.types.{StringType, StructType}
import feast.ingestion.utils.StringUtils
import feast.ingestion.stores.serialization.Serializer
import org.apache.hadoop.security.UserGroupInformation
import org.apache.spark.SparkEnv
Expand Down Expand Up @@ -154,7 +155,7 @@ class BigTableSinkRelation(

private def tableName: String = {
val entities = config.entityColumns.mkString("__")
s"${config.projectName}__${entities}"
StringUtils.trimAndHash(s"${config.projectName}__${entities}", maxTableNameLength)
}

private def joinEntityKey: UserDefinedFunction = udf { r: Row =>
Expand All @@ -164,6 +165,7 @@ class BigTableSinkRelation(
private val metadataColumnFamily = "metadata"
private val schemaKeyPrefix = "schema#"
private val emptyQualifier = ""
private val maxTableNameLength = 50

private def isSystemColumn(name: String) =
(config.entityColumns ++ Seq(config.timestampColumn)).contains(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package feast.ingestion.stores.cassandra

import feast.ingestion.utils.StringUtils
import feast.ingestion.stores.serialization.Serializer
import org.apache.spark.sql.expressions.UserDefinedFunction
import org.apache.spark.sql.functions.{col, lit, struct, udf}
Expand Down Expand Up @@ -63,8 +64,11 @@ class CassandraSinkRelation(
writer.append()
}

val maxTableNameLength = 48

def sanitizedForCassandra(expr: String): String = {
expr.replace('-', '_')
val replacedString = expr.replace('-', '_')
StringUtils.trimAndHash(replacedString, maxTableNameLength)
}

val tableName = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2018-2021 The Feast Authors
*
* Licensed 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
*
* https://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 feast.ingestion.utils

import com.google.common.hash.Hashing

object StringUtils {
private def suffixHash(expr: String): String = {
Hashing.murmur3_32().hashBytes(expr.getBytes).toString
}

def trimAndHash(expr: String, maxLength: Int): String = {
val maxPrefixLength = 40
Comment thread
pyalex marked this conversation as resolved.
Outdated
if (expr.length > maxLength)
expr
.take(maxPrefixLength)
.concat(suffixHash(expr.substring(maxPrefixLength)))
else
expr
}
}