Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions amber/src/main/scala/org/apache/texera/web/auth/JwtAuth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import io.dropwizard.setup.Environment
import org.apache.texera.auth.JwtAuth.jwtConsumer
import org.apache.texera.auth.SessionUser

// TODO: move this logic to Auth
@Deprecated
// TODO: move this logic to common/auth once it depends on Dropwizard, so amber
// services can drop the toastshaman dropwizard-auth-jwt filter.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the deprecated is a behavior change. Let's keep the deprecation. It is fine to keep that in warning. The way to remove this warning is to actually remove this code

object JwtAuth {
def setupJwtAuth(environment: Environment): Unit = {
// register JWT Auth layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import java.lang.Byte.{SIZE => BitsPerByte}
import java.util.UUID
import scala.collection.mutable
import scala.concurrent.duration.DurationInt
import scala.language.existentials

object ExecutionResultService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ package org.apache.texera.amber.pybuilder

import scala.reflect.macros.blackbox

object BoundaryValidator {

final case class CompileTimeContext[Pos](
leftPart: String,
rightPart: String,
prefixSource: String,
argIndex: Int,
errorPos: Pos
)

final case class RuntimeContext(
leftPart: String,
rightPart: String,
prefixSource: String,
argIndex: Int
)
}

/**
* Macro-only helper: validates boundaries for Encodable insertions.
*
Expand All @@ -30,6 +48,7 @@ import scala.reflect.macros.blackbox
final class BoundaryValidator[C <: blackbox.Context](val c: C) {
import PythonLexerUtils._
import c.universe._
import BoundaryValidator.{CompileTimeContext, RuntimeContext}

/**
* Centralized, templatized error messages (Option A).
Expand Down Expand Up @@ -75,22 +94,7 @@ final class BoundaryValidator[C <: blackbox.Context](val c: C) {
"Add whitespace or punctuation to separate tokens."
}

final case class CompileTimeContext(
leftPart: String,
rightPart: String,
prefixSource: String,
argIndex: Int,
errorPos: Position
)

final case class RuntimeContext(
leftPart: String,
rightPart: String,
prefixSource: String,
argIndex: Int
)

def validateCompileTime(ctx: CompileTimeContext): Unit = {
def validateCompileTime(ctx: CompileTimeContext[Position]): Unit = {
val prefixLine = lineTail(ctx.prefixSource)
val argNum = ctx.argIndex + 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,13 @@ object PythonTemplateBuilder {
if (argExpr.tree.pos != NoPosition) argExpr.tree.pos else macroCtx.enclosingPosition

validator.validateCompileTime(
validator.CompileTimeContext(leftPart, rightPart, prefixSource, argIndex, errorPos)
BoundaryValidator.CompileTimeContext(
leftPart,
rightPart,
prefixSource,
argIndex,
errorPos
)
)

case _ => // no-op
Expand Down Expand Up @@ -414,7 +420,7 @@ object PythonTemplateBuilder {

val argIdent = Ident(TermName(s"__pyb_arg$argIndex"))
validator.runtimeChecksForNestedBuilder(
validator.RuntimeContext(leftPart, rightPart, prefixSource, argIndex),
BoundaryValidator.RuntimeContext(leftPart, rightPart, prefixSource, argIndex),
argIdent
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.apache.texera.amber.operator.keywordSearch.KeywordSearchOpDesc
import org.apache.texera.amber.operator.source.scan.csv.CSVScanSourceOpDesc
import org.apache.texera.amber.operator.source.scan.json.JSONLScanSourceOpDesc
import org.apache.texera.amber.operator.source.sql.asterixdb.AsterixDBSourceOpDesc
import org.apache.texera.amber.operator.source.sql.mysql.MySQLSourceOpDesc
import org.apache.texera.amber.operator.udf.python.PythonUDFOpDescV2
import org.apache.texera.amber.operator.udf.python.source.PythonUDFSourceOpDescV2

Expand Down Expand Up @@ -140,25 +139,6 @@ object TestOperators {
aggOp
}

def inMemoryMySQLSourceOpDesc(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL exec implementation was disabled due to license issue. We can remove this (used for test) for now. @bobbai00 whats our plan to add mysql back?

host: String,
port: String,
database: String,
table: String,
username: String,
password: String
): MySQLSourceOpDesc = {
val inMemoryMySQLSourceOpDesc = new MySQLSourceOpDesc()
inMemoryMySQLSourceOpDesc.host = host
inMemoryMySQLSourceOpDesc.port = port
inMemoryMySQLSourceOpDesc.database = database
inMemoryMySQLSourceOpDesc.table = table
inMemoryMySQLSourceOpDesc.username = username
inMemoryMySQLSourceOpDesc.password = password
inMemoryMySQLSourceOpDesc.limit = Some(1000)
inMemoryMySQLSourceOpDesc
}

// TODO: use mock data to perform the test, remove dependency on the real AsterixDB
def asterixDBSourceOpDesc(): AsterixDBSourceOpDesc = {
val asterixDBOp = new AsterixDBSourceOpDesc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.apache.texera.service.type.DatasetFileNode;
import scala.collection.JavaConverters;
import scala.collection.immutable.List;
import scala.jdk.javaapi.CollectionConverters;

import java.io.IOException;

Expand Down Expand Up @@ -53,7 +53,7 @@ public void serialize(DatasetFileNode value, JsonGenerator gen, SerializerProvid
gen.writeFieldName("children");
gen.writeStartArray();
List<DatasetFileNode> children = value.getChildren();
for (DatasetFileNode child : JavaConverters.seqAsJavaList(children)) {
for (DatasetFileNode child : CollectionConverters.asJava(children)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we turn this one into an error? So that it can prevent the wrong pattern being introduced again.

serialize(child, gen, provider); // Recursively serialize children
}
gen.writeEndArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 org.apache.texera.service.`type`.serde

import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import org.apache.texera.service.`type`.DatasetFileNode
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class DatasetFileNodeSerializerSpec extends AnyFlatSpec with Matchers {

private val mapper: ObjectMapper = {
val m = new ObjectMapper()
// DefaultScalaModule lets Jackson unwrap scala.Option for the "size" field.
m.registerModule(DefaultScalaModule)
val module = new SimpleModule()
module.addSerializer(classOf[DatasetFileNode], new DatasetFileNodeSerializer())
m.registerModule(module)
m
}

private def asJson(node: DatasetFileNode): JsonNode =
mapper.readTree(mapper.writeValueAsString(node))

// The serializer dereferences value.getParent().getFilePath(), so every node it
// sees needs a non-null parent. Tests build a tree rooted at "/" and serialize
// its descendants.
private def rootDir: DatasetFileNode =
new DatasetFileNode("/", "directory", null, "")

"DatasetFileNodeSerializer" should "serialize a file node with size and no children field" in {
val root = rootDir
val owner = new DatasetFileNode("alice@example.com", "directory", root, "alice@example.com")
val file = new DatasetFileNode("data.csv", "file", owner, "alice@example.com", Some(100L))

val json = asJson(file)

json.get("name").asText() shouldBe "data.csv"
json.get("type").asText() shouldBe "file"
json.get("parentDir").asText() shouldBe "/alice@example.com"
json.get("ownerEmail").asText() shouldBe "alice@example.com"
json.get("size").asLong() shouldBe 100L
json.has("children") shouldBe false
}

it should "recursively serialize a directory and its children" in {
val root = rootDir
val owner = new DatasetFileNode("alice@example.com", "directory", root, "alice@example.com")
val file = new DatasetFileNode("data.csv", "file", owner, "alice@example.com", Some(100L))
val subdir = new DatasetFileNode("subdir", "directory", owner, "alice@example.com")
val nested = new DatasetFileNode("nested.txt", "file", subdir, "alice@example.com", Some(200L))
subdir.children = Some(List(nested))
owner.children = Some(List(file, subdir))

val json = asJson(owner)

json.get("name").asText() shouldBe "alice@example.com"
json.get("type").asText() shouldBe "directory"
json.get("parentDir").asText() shouldBe "/"
val children = json.get("children")
children.isArray shouldBe true
children.size() shouldBe 2
children.get(0).get("name").asText() shouldBe "data.csv"
children.get(0).get("size").asLong() shouldBe 100L
children.get(1).get("name").asText() shouldBe "subdir"
children.get(1).get("children").get(0).get("name").asText() shouldBe "nested.txt"
children.get(1).get("children").get(0).get("size").asLong() shouldBe 200L
}

it should "emit an empty children array for a directory with no children" in {
val root = rootDir
val empty = new DatasetFileNode("empty", "directory", root, "alice@example.com")

val json = asJson(empty)

json.get("type").asText() shouldBe "directory"
val children = json.get("children")
children.isArray shouldBe true
children.size() shouldBe 0
}
}
Loading