in modules/spark-ext/spark/src/main/scala/org/apache/ignite/spark/impl/optimization/SimpleExpressions.scala [129:191]
private def aliasToString(column: String, alias: String): String =
if (isAliasEqualColumnName(alias, column))
column
else if (alias.matches("[A-Za-z_][0-9A-Za-z_]*"))
s"$column AS $alias"
else
s"""$column AS "$alias""""
/**
* @param alias Alias.
* @param column Column.
* @return True if name equals to alias, false otherwise.
*/
private def isAliasEqualColumnName(alias: String, column: String): Boolean =
alias.compareToIgnoreCase(column.replaceAll("'", "")) == 0
/**
* @param from From type conversion.
* @param to To type conversion.
* @return True if cast support for types, false otherwise.
*/
private def castSupported(from: DataType, to: DataType): Boolean = from match {
case BooleanType ⇒
Set[DataType](BooleanType, StringType)(to)
case ByteType ⇒
Set(ByteType, ShortType, IntegerType, LongType, FloatType, DoubleType, StringType, DecimalType(_, _),
StringType)(to)
case ShortType ⇒
Set(ShortType, IntegerType, LongType, FloatType, DoubleType, StringType, DecimalType(_, _))(to)
case IntegerType ⇒
Set(IntegerType, LongType, FloatType, DoubleType, StringType, DecimalType(_, _))(to)
case LongType ⇒
Set(LongType, FloatType, DoubleType, StringType, DecimalType(_, _))(to)
case FloatType ⇒
Set(FloatType, DoubleType, StringType, DecimalType(_, _))(to)
case DoubleType ⇒
Set(DoubleType, StringType, DecimalType(_, _))(to)
case DecimalType() ⇒
Set(StringType, DecimalType(_, _))(to)
case DateType ⇒
Set[DataType](DateType, StringType, LongType, TimestampType)(to)
case TimestampType ⇒
Set[DataType](TimestampType, DateType, StringType, LongType)(to)
case StringType ⇒
Set(BooleanType, ByteType, ShortType, IntegerType, LongType, FloatType, DoubleType,
DecimalType(_, _), DateType, TimestampType, StringType)(to)
case BinaryType ⇒
false
case ArrayType(_, _) ⇒
false
}