|
17 | 17 |
|
18 | 18 | package org.apache.spark.sql.catalyst |
19 | 19 |
|
| 20 | + |
20 | 21 | /** |
21 | | - * Identifies a table in a database. |
22 | | - * If `database` is not defined, the current database is used. |
| 22 | + * An identifier that optionally specifies a database. |
| 23 | + * |
| 24 | + * Format (unquoted): "name" or "db.name" |
| 25 | + * Format (quoted): "`name`" or "`db`.`name`" |
23 | 26 | */ |
24 | | -private[sql] case class TableIdentifier(table: String, database: Option[String]) { |
25 | | - def this(table: String) = this(table, None) |
26 | | - |
| 27 | +private[sql] abstract class IdentifierWithDatabase(name: String) { |
| 28 | + def database: Option[String] |
| 29 | + def quotedString: String = database.map(db => s"`$db`.`$name`").getOrElse(s"`$name`") |
| 30 | + def unquotedString: String = database.map(db => s"$db.$name").getOrElse(name) |
27 | 31 | override def toString: String = quotedString |
| 32 | +} |
| 33 | + |
28 | 34 |
|
29 | | - def quotedString: String = database.map(db => s"`$db`.`$table`").getOrElse(s"`$table`") |
| 35 | +/** |
| 36 | + * Identifies a table in a database. |
| 37 | + * If `database` is not defined, the current database is used. |
| 38 | + */ |
| 39 | +private[sql] case class TableIdentifier( |
| 40 | + table: String, |
| 41 | + database: Option[String]) |
| 42 | + extends IdentifierWithDatabase(table) { |
30 | 43 |
|
31 | | - def unquotedString: String = database.map(db => s"$db.$table").getOrElse(table) |
| 44 | + def this(name: String) = this(name, None) |
32 | 45 | } |
33 | 46 |
|
34 | 47 | private[sql] object TableIdentifier { |
35 | | - def apply(tableName: String): TableIdentifier = new TableIdentifier(tableName) |
| 48 | + def apply(tableName: String): TableIdentifier = TableIdentifier(tableName) |
36 | 49 | } |
37 | 50 |
|
| 51 | + |
38 | 52 | /** |
39 | 53 | * Identifies a function in a database. |
40 | 54 | * If `database` is not defined, the current database is used. |
41 | 55 | */ |
42 | | -// TODO: reuse some code with TableIdentifier. |
43 | | -private[sql] case class FunctionIdentifier(funcName: String, database: Option[String]) { |
44 | | - def this(name: String) = this(name, None) |
| 56 | +private[sql] case class FunctionIdentifier( |
| 57 | + funcName: String, |
| 58 | + database: Option[String]) |
| 59 | + extends IdentifierWithDatabase(funcName) { |
45 | 60 |
|
46 | | - override def toString: String = quotedString |
47 | | - |
48 | | - def quotedString: String = database.map(db => s"`$db`.`$funcName`").getOrElse(s"`$funcName`") |
49 | | - |
50 | | - def unquotedString: String = database.map(db => s"$db.$funcName").getOrElse(funcName) |
| 61 | + def this(name: String) = this(name, None) |
51 | 62 | } |
52 | 63 |
|
53 | 64 | private[sql] object FunctionIdentifier { |
|
0 commit comments