-
Notifications
You must be signed in to change notification settings - Fork 124
fix: admin-adjustable max columns with a clear overflow message #4669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7a15e95
admin-adjustable max columns with a clear overflow message
Ma77Ball 36e3657
ran lint for pr
Ma77Ball e75bd49
Merge branch 'main' into fix/adjustable_univocity
Ma77Ball 325a63f
Merge branch 'main' into fix/adjustable_univocity
chenlica 29b35f7
Merge branch 'apache:main' into fix/adjustable_univocity
Ma77Ball 09e20af
fixed frontend error for ci test cases
Ma77Ball a426b35
added nztable module and working on fixing ci failures
Ma77Ball 7fb01ba
Merge branch 'main' into fix/adjustable_univocity
chenlica f5dc500
Merge branch 'main' into fix/adjustable_univocity
chenlica 386e1a3
removed the columns per result panel setting
Ma77Ball b3cbf54
removed result table columns from default config file)
Ma77Ball bfc87e3
Merge branch 'main' into fix/adjustable_univocity
chenlica 740eab8
Merge branch 'main' of github.com:apache/texera into fix/adjustable_u…
Ma77Ball 869a85b
Merge branch 'fix/adjustable_univocity' of github.com:Ma77Ball/texera…
Ma77Ball 2d20ad7
Removed old config for column limit on result panel
Ma77Ball c77b7c6
removed unused csv block from default.conf
Ma77Ball 1e658eb
changing forall to exists to cover column overflows
Ma77Ball 7f1c6e5
Added test case for the parseOrDefault
Ma77Ball 423ac90
Merge branch 'main' into fix/adjustable_univocity
aglinxinyuan cbc534e
added line back in default.conf
Ma77Ball dba71ed
Merge remote-tracking branch 'origin/fix/adjustable_univocity' into f…
Ma77Ball 083a091
ArrayIndexOutOfBoundsException added test
Ma77Ball cb2aa5c
ran lint with yarn
Ma77Ball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
common/dao/src/main/scala/org/apache/texera/dao/SiteSettings.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * 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.dao | ||
|
|
||
| import org.jooq.impl.DSL | ||
|
|
||
| import scala.util.Try | ||
|
|
||
| /** | ||
| * Read-side accessor for the `site_settings` key/value table that admin pages | ||
| * write through. Centralises the "look up by key, parse, fall back on any | ||
| * failure" pattern that previously lived inline in ConfigResource, | ||
| * CSVScanSourceOpExec, and DatasetResource. | ||
| * | ||
| * Failures swallowed by the outer Try include: SqlServer not initialised | ||
| * (e.g. on workers in distributed mode), no row for the key, and value that | ||
| * can't be parsed. In all of these cases the caller's default takes over. | ||
| */ | ||
| object SiteSettings { | ||
|
|
||
| def getInt(key: String, default: => Int): Int = | ||
| readAndParse(key, default)(_.toInt) | ||
|
|
||
| def getLong(key: String, default: => Long): Long = | ||
| readAndParse(key, default)(_.toLong) | ||
|
|
||
| private[dao] def parseOrDefault[T](raw: Option[String], default: T)(parse: String => T): T = | ||
| raw.flatMap(s => Try(parse(s.trim)).toOption).getOrElse(default) | ||
|
|
||
| private def readAndParse[T](key: String, default: => T)(parse: String => T): T = | ||
| Try { | ||
| val raw = SqlServer | ||
| .getInstance() | ||
| .createDSLContext() | ||
| .select(DSL.field("value", classOf[String])) | ||
| .from(DSL.table(DSL.name("texera_db", "site_settings"))) | ||
| .where(DSL.field("key", classOf[String]).eq(key)) | ||
| .fetchOneInto(classOf[String]) | ||
| parseOrDefault(Option(raw), default)(parse) | ||
| }.getOrElse(default) | ||
| } | ||
45 changes: 45 additions & 0 deletions
45
common/dao/src/test/scala/org/apache/texera/dao/SiteSettingsSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.dao | ||
|
|
||
| import org.scalatest.flatspec.AnyFlatSpec | ||
| import org.scalatest.matchers.should.Matchers | ||
|
|
||
| class SiteSettingsSpec extends AnyFlatSpec with Matchers { | ||
|
|
||
| "parseOrDefault" should "return the parsed value when the raw string is present and valid" in { | ||
| SiteSettings.parseOrDefault(Some("42"), 0)(_.toInt) shouldBe 42 | ||
| } | ||
|
|
||
| it should "return the default when the Option is None" in { | ||
| SiteSettings.parseOrDefault(None, 99)(_.toInt) shouldBe 99 | ||
| } | ||
|
|
||
| it should "return the default when the string cannot be parsed" in { | ||
| SiteSettings.parseOrDefault(Some("not-a-number"), 7)(_.toInt) shouldBe 7 | ||
| } | ||
|
|
||
| it should "trim whitespace before parsing" in { | ||
| SiteSettings.parseOrDefault(Some(" 100 "), 0)(_.toInt) shouldBe 100 | ||
| } | ||
|
|
||
| it should "work for Long values" in { | ||
| SiteSettings.parseOrDefault(Some("9999999999"), 0L)(_.toLong) shouldBe 9999999999L | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...test/scala/org/apache/texera/amber/operator/source/scan/csv/CSVScanSourceOpExecSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * 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.amber.operator.source.scan.csv | ||
|
|
||
| import com.univocity.parsers.common.TextParsingException | ||
| import com.univocity.parsers.csv.{CsvParser, CsvParserSettings} | ||
| import org.scalatest.flatspec.AnyFlatSpec | ||
|
|
||
| import java.io.StringReader | ||
|
|
||
| /** | ||
| * Verifies the column-overflow translation in [[CSVScanSourceOpExec.parseNextRow]] | ||
| * — the path that turns a deep Univocity stack trace into a single-sentence message | ||
| * the workflow user can act on. | ||
| */ | ||
| class CSVScanSourceOpExecSpec extends AnyFlatSpec { | ||
|
|
||
| private def parserWithMaxColumns(max: Int): CsvParser = { | ||
| val settings = new CsvParserSettings() | ||
| settings.setMaxColumns(max) | ||
| settings.setMaxCharsPerColumn(-1) | ||
| new CsvParser(settings) | ||
| } | ||
|
|
||
| "parseNextRow" should "return the parsed row when the input is within the column limit" in { | ||
| val parser = parserWithMaxColumns(10) | ||
| parser.beginParsing(new StringReader("a,b,c\n")) | ||
|
|
||
| val row = CSVScanSourceOpExec.parseNextRow(parser, 10) | ||
|
|
||
| assert(row.toSeq == Seq("a", "b", "c")) | ||
| } | ||
|
|
||
| it should "return null at end of input (so the iterator can terminate cleanly)" in { | ||
| val parser = parserWithMaxColumns(10) | ||
| parser.beginParsing(new StringReader("")) | ||
|
|
||
| assert(CSVScanSourceOpExec.parseNextRow(parser, 10) == null) | ||
| } | ||
|
|
||
| it should "translate a column-overflow TextParsingException into a clear user message" in { | ||
| val maxColumns = 2 | ||
| val parser = parserWithMaxColumns(maxColumns) | ||
| parser.beginParsing(new StringReader("a,b,c,d,e\n")) | ||
|
|
||
| val ex = intercept[RuntimeException] { | ||
| CSVScanSourceOpExec.parseNextRow(parser, maxColumns) | ||
| } | ||
|
|
||
| // The message must mention the configured limit so the user knows what was hit. | ||
| assert(ex.getMessage.contains(maxColumns.toString)) | ||
| assert(ex.getMessage.toLowerCase.contains("max columns")) | ||
| assert(ex.getMessage.toLowerCase.contains("exceeded")) | ||
| // The original Univocity exception is preserved as the cause so developers | ||
| // can still inspect the underlying parser state if needed. | ||
| assert(ex.getCause.isInstanceOf[TextParsingException]) | ||
| } | ||
|
|
||
| "isColumnOverflow" should "detect AIOOBE causes from Java 8's plain-integer message" in { | ||
| val cause = new ArrayIndexOutOfBoundsException("5") | ||
| val ex = new TextParsingException(null, "wrapper", cause) | ||
| assert(CSVScanSourceOpExec.isColumnOverflow(ex, maxColumns = 5)) | ||
| assert(!CSVScanSourceOpExec.isColumnOverflow(ex, maxColumns = 6)) | ||
| } | ||
|
|
||
| it should "detect AIOOBE causes from Java 9+'s 'Index N out of bounds for length M' message" in { | ||
| val cause = new ArrayIndexOutOfBoundsException("Index 5 out of bounds for length 5") | ||
| val ex = new TextParsingException(null, "wrapper", cause) | ||
| assert(CSVScanSourceOpExec.isColumnOverflow(ex, maxColumns = 5)) | ||
| assert(!CSVScanSourceOpExec.isColumnOverflow(ex, maxColumns = 6)) | ||
| } | ||
|
|
||
| it should "ignore TextParsingExceptions whose cause is unrelated" in { | ||
| val unrelated = new TextParsingException(null, "Some other parsing problem") | ||
| val withDifferentCause = | ||
| new TextParsingException(null, "wrapper", new IllegalStateException("nope")) | ||
| assert(!CSVScanSourceOpExec.isColumnOverflow(unrelated, maxColumns = 5)) | ||
| assert(!CSVScanSourceOpExec.isColumnOverflow(withDifferentCause, maxColumns = 5)) | ||
|
Ma77Ball marked this conversation as resolved.
|
||
| } | ||
|
|
||
| it should "ignore an AIOOBE whose message cannot be parsed as an index" in { | ||
| val unparseable = new ArrayIndexOutOfBoundsException("something went wrong") | ||
| val ex = new TextParsingException(null, "wrapper", unparseable) | ||
| assert(!CSVScanSourceOpExec.isColumnOverflow(ex, maxColumns = 5)) | ||
| } | ||
|
|
||
| "columnOverflowMessage" should "include the configured maximum so the user knows the current limit" in { | ||
| val msg = CSVScanSourceOpExec.columnOverflowMessage(750) | ||
| assert(msg.contains("750")) | ||
| assert(msg.toLowerCase.contains("max columns")) | ||
| assert(msg.toLowerCase.contains("exceeded")) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.