Skip to content

Commit

Permalink
GEOMESA-3293 Provide error message if trying to ingest from stdin wit…
Browse files Browse the repository at this point in the history
…hout a converter (#3035)
  • Loading branch information
adeet1 authored Jan 24, 2024
1 parent 86da2f5 commit 3cbd9a6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.locationtech.geomesa.accumulo.tools.ingest

import com.beust.jcommander.ParameterException
import com.typesafe.config.{ConfigFactory, ConfigRenderOptions}
import org.apache.commons.io.IOUtils
import org.junit.runner.RunWith
Expand Down Expand Up @@ -112,6 +113,54 @@ class IngestCommandTest extends Specification {
}
}

"fail to ingest from stdin if no converter is specified" in {
val confFile = new File(getClass.getClassLoader.getResource("examples/example1-csv.conf").getFile)
val dataFile = WithClose(getClass.getClassLoader.getResourceAsStream("examples/example1.csv")) { in =>
IOUtils.toByteArray(in)
}
val input = new ByteArrayInputStream(dataFile)

val args = baseArgs ++ Array("-s", confFile.getPath, "-")

val command = AccumuloRunner.parseCommand(args).asInstanceOf[AccumuloDataStoreCommand]

val in = System.in
in.synchronized {
try {
System.setIn(input)
command.execute() must throwA[ParameterException].like {
case e => e.getMessage mustEqual "Cannot infer types from stdin - please specify a converter/sft or ingest from a file"
}
} finally {
System.setIn(in)
}
}
}

"fail to ingest from stdin if no sft is specified" in {
val confFile = new File(getClass.getClassLoader.getResource("examples/example1-csv.conf").getFile)
val dataFile = WithClose(getClass.getClassLoader.getResourceAsStream("examples/example1.csv")) { in =>
IOUtils.toByteArray(in)
}
val input = new ByteArrayInputStream(dataFile)

val args = baseArgs ++ Array("--converter", confFile.getPath, "-")

val command = AccumuloRunner.parseCommand(args).asInstanceOf[AccumuloDataStoreCommand]

val in = System.in
in.synchronized {
try {
System.setIn(input)
command.execute() must throwA[ParameterException].like {
case e => e.getMessage mustEqual "SimpleFeatureType name and/or specification argument is required"
}
} finally {
System.setIn(in)
}
}
}

"not ingest csv to tsv " in {
val confFile = new File(getClass.getClassLoader.getResource("examples/example1-tsv.conf").getFile)
val dataFile = new File(getClass.getClassLoader.getResource("examples/example1.csv").getFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ object IngestCommand extends LazyLogging {
var converter: Config = Option(params.config).map(CLArgResolver.getConfig).orNull

if (converter == null && inputs.nonEmpty) {
// ingesting from stdin without specifying a converter is not supported
if (inputs == Inputs.StdInInputs) {
throw new ParameterException("Cannot infer types from stdin - please specify a converter/sft or ingest from a file")
}

// if there is no converter passed in, try to infer the schema from the input files themselves
Command.user.info("No converter defined - will attempt to detect schema from input files")
val file = inputs.iterator.flatMap(PathUtils.interpretPath).headOption.getOrElse {
Expand Down

0 comments on commit 3cbd9a6

Please sign in to comment.