Skip to content

Commit

Permalink
Improve some styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimahriman committed Jan 20, 2024
1 parent bb77ae7 commit 4d04e41
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,21 @@ class CodegenContext extends Logging {
*/
var currentLambdaVars: mutable.Map[Long, ExprCode] = mutable.HashMap.empty

def withLambdaVars(namedLambdas: Seq[NamedLambdaVariable],
def withLambdaVars(
namedLambdas: Seq[NamedLambdaVariable],
f: Seq[ExprCode] => ExprCode): ExprCode = {
val lambdaVars = namedLambdas.map { namedLambda =>
val id = namedLambda.exprId.id
val lambdaVars = namedLambdas.map { lambda =>
val id = lambda.exprId.id
if (currentLambdaVars.get(id).nonEmpty) {
throw QueryExecutionErrors.lambdaVariableAlreadyDefinedError(id)
}
val isNull = if (namedLambda.nullable) {
val isNull = if (lambda.nullable) {
JavaCode.isNullGlobal(addMutableState(JAVA_BOOLEAN, "lambdaIsNull"))
} else {
FalseLiteral
}
val value = addMutableState(javaType(namedLambda.dataType), "lambdaValue")
val lambdaVar = ExprCode(isNull, JavaCode.global(value, namedLambda.dataType))
val value = addMutableState(javaType(lambda.dataType), "lambdaValue")
val lambdaVar = ExprCode(isNull, JavaCode.global(value, lambda.dataType))
currentLambdaVars.put(id, lambdaVar)
lambdaVar
}
Expand All @@ -201,7 +202,8 @@ class CodegenContext extends Logging {
}

def getLambdaVar(id: Long): ExprCode = {
currentLambdaVars.getOrElse(id,
currentLambdaVars.getOrElse(
id,
throw QueryExecutionErrors.lambdaVariableNotDefinedError(id))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ trait HigherOrderFunction extends Expression with ExpectsInputTypes {
}


protected def assignAtomic(atomicRef: String, value: String, isNull: String = FalseLiteral,
protected def assignAtomic(
atomicRef: String,
value: String,
isNull: String = FalseLiteral,
nullable: Boolean = false) = {
if (nullable) {
s"""
Expand All @@ -262,8 +265,12 @@ trait HigherOrderFunction extends Expression with ExpectsInputTypes {
}
}

protected def assignArrayElement(ctx: CodegenContext, arrayName: String, elementCode: ExprCode,
elementVar: NamedLambdaVariable, index: String): String = {
protected def assignArrayElement(
ctx: CodegenContext,
arrayName: String,
elementCode: ExprCode,
elementVar: NamedLambdaVariable,
index: String): String = {
val elementType = elementVar.dataType
val elementAtomic = ctx.addReferenceObj(elementVar.name, elementVar.value)
val extractElement = CodeGenerator.getValue(arrayName, elementType, index)
Expand All @@ -284,8 +291,11 @@ trait HigherOrderFunction extends Expression with ExpectsInputTypes {
}
}

protected def assignIndex(ctx: CodegenContext, indexCode: ExprCode,
indexVar: NamedLambdaVariable, index: String): String = {
protected def assignIndex(
ctx: CodegenContext,
indexCode: ExprCode,
indexVar: NamedLambdaVariable,
index: String): String = {
val indexAtomic = ctx.addReferenceObj(indexVar.name, indexVar.value)
s"""
${indexCode.value} = $index;
Expand Down Expand Up @@ -1177,7 +1187,10 @@ case class ArrayAggregate(
}
}

protected def assignVar(varCode: ExprCode, value: String, isNull: String,
protected def assignVar(
varCode: ExprCode,
value: String,
isNull: String,
nullable: Boolean): String = {
if (nullable) {
s"""
Expand Down

0 comments on commit 4d04e41

Please sign in to comment.