Skip to content

Commit

Permalink
Merge pull request #249 from nrkno/bqjobid-bugfix
Browse files Browse the repository at this point in the history
Ensure the names of jobIds
  • Loading branch information
hamnis authored Jan 11, 2024
2 parents 751fc69 + 6ed1fc1 commit bc4bcf1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/scala/no/nrk/bigquery/BQJobId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ final case class BQJobId(
copy(projectId = defaults.map(_.projectId), locationId = defaults.map(_.locationId))
} else this

def +(str: String): BQJobId = copy(name = name + str)
def append(str: String): BQJobId = copy(name = name + str)
def +(str: String): BQJobId = append(str)
def append(str: String): BQJobId = copy(name = BQJobId.mkName(name + str))
}

object BQJobId {
Expand All @@ -43,9 +43,12 @@ object BQJobId {
def apply(name: String): BQJobId = apply(name, JobLabels.empty)
def apply(name: String, labels: JobLabels): BQJobId = BQJobId(None, None, mkName(name), labels)

private def mkName(str: String): String =
str
private def mkName(str: String): String = {
val replaced = str
.replace("anonfun", "") // generated from `sourcecode.Enclosing`
.replace('.', '_')
.filter(c => c.isLetterOrDigit || c == '_')
replaced.substring(0, Math.min(replaced.length, 1024))
}

}

0 comments on commit bc4bcf1

Please sign in to comment.