-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-10310][SQL]Using \t as the field delimeter and \n as the line delimeter #8476
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cafe301
tab as the field delimeter and 10 as the line delimeter
zhichao-li 4939ed8
add some idea from hive
zhichao-li 517f31f
style
zhichao-li 23aaa04
fix cast
zhichao-li c6e9134
add unittest for script input and output format
zhichao-li 9b3a8de
fix path of testing script
zhichao-li 8fb75a6
style
zhichao-li 2d1e604
fix script
zhichao-li ae0b68e
python3
zhichao-li 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
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 |
|---|---|---|
|
|
@@ -21,20 +21,21 @@ import java.io._ | |
| import java.util.Properties | ||
| import javax.annotation.Nullable | ||
|
|
||
| import org.apache.hadoop.util.LineReader | ||
|
|
||
| import scala.collection.JavaConverters._ | ||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.hadoop.hive.serde.serdeConstants | ||
| import org.apache.hadoop.hive.serde2.AbstractSerDe | ||
| import org.apache.hadoop.hive.serde2.objectinspector._ | ||
| import org.apache.hadoop.io.Writable | ||
| import org.apache.hadoop.io.{Text, Writable} | ||
|
|
||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.sql.catalyst.{CatalystTypeConverters, InternalRow} | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.plans.logical.ScriptInputOutputSchema | ||
| import org.apache.spark.sql.execution._ | ||
| import org.apache.spark.sql.hive.HiveShim._ | ||
| import org.apache.spark.sql.hive.{HiveContext, HiveInspectors} | ||
| import org.apache.spark.sql.types.DataType | ||
| import org.apache.spark.util.{CircularBuffer, RedirectThread, Utils} | ||
|
|
@@ -108,7 +109,7 @@ case class ScriptTransformation( | |
| val reader = new BufferedReader(new InputStreamReader(inputStream)) | ||
| val outputIterator: Iterator[InternalRow] = new Iterator[InternalRow] with HiveInspectors { | ||
| var curLine: String = null | ||
| val scriptOutputStream = new DataInputStream(inputStream) | ||
| val lineReader = new LineReader(inputStream) | ||
| var scriptOutputWritable: Writable = null | ||
| val reusedWritableObject: Writable = if (null != outputSerde) { | ||
| outputSerde.getSerializedClass().newInstance | ||
|
|
@@ -134,15 +135,13 @@ case class ScriptTransformation( | |
| } | ||
| } else if (scriptOutputWritable == null) { | ||
| scriptOutputWritable = reusedWritableObject | ||
| try { | ||
| scriptOutputWritable.readFields(scriptOutputStream) | ||
| if (0 == lineReader.readLine(scriptOutputWritable.asInstanceOf[Text])) { | ||
| if (writerThread.exception.isDefined) { | ||
| throw writerThread.exception.get | ||
| } | ||
| false | ||
| } else { | ||
| true | ||
| } catch { | ||
| case _: EOFException => | ||
| if (writerThread.exception.isDefined) { | ||
| throw writerThread.exception.get | ||
| } | ||
| false | ||
| } | ||
| } else { | ||
| true | ||
|
|
@@ -222,7 +221,7 @@ private class ScriptTransformationWriterThread( | |
|
|
||
| override def run(): Unit = Utils.logUncaughtExceptions { | ||
| TaskContext.setTaskContext(taskContext) | ||
|
|
||
| val newLineCode = 10 | ||
| val dataOutputStream = new DataOutputStream(outputStream) | ||
|
|
||
| // We can't use Utils.tryWithSafeFinally here because we also need a `catch` block, so | ||
|
|
@@ -248,9 +247,10 @@ private class ScriptTransformationWriterThread( | |
| } | ||
| outputStream.write(data.getBytes("utf-8")) | ||
| } else { | ||
| val writable = inputSerde.serialize( | ||
| row.asInstanceOf[GenericInternalRow].values, inputSoi) | ||
| prepareWritable(writable, ioschema.outputSerdeProps).write(dataOutputStream) | ||
| val text = inputSerde.serialize( | ||
| row.asInstanceOf[GenericInternalRow].values, inputSoi).asInstanceOf[Text] | ||
| outputStream.write(text.getBytes(), 0, text.getLength()) | ||
| outputStream.write(newLineCode) | ||
| } | ||
| } | ||
| outputStream.close() | ||
|
|
@@ -340,6 +340,7 @@ case class HiveScriptIOSchema ( | |
|
|
||
| var propsMap = serdeProps.toMap + (serdeConstants.LIST_COLUMNS -> columns.mkString(",")) | ||
| propsMap = propsMap + (serdeConstants.LIST_COLUMN_TYPES -> columnTypesNames) | ||
| propsMap = propsMap + (serdeConstants.FIELD_DELIM -> "\t") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we specify line delimiter here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line delimiter is control by RecorderWriter, see TextRecordWriter as an example: public void write(Writable row) throws IOException {
Text text = (Text) row;
Text escapeText = text;
if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVESCRIPTESCAPE)) {
escapeText = HiveUtils.escapeText(text);
}
out.write(escapeText.getBytes(), 0, escapeText.getLength());
out.write(Utilities.newLineCode);
} |
||
|
|
||
| val properties = new Properties() | ||
| properties.putAll(propsMap.asJava) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems never used.