Чтобы записать CSV-файл с заголовками и переименовать файл part-000 в .csv.gzip
DF.coalesce(1).write.format("com.databricks.spark.csv").mode("overwrite")
.option("header","true")
.option("codec",org.apache.hadoop.io.compress.GzipCodec").save(tempLocationFileName)
copyRename(tempLocationFileName, finalLocationFileName)
def copyRename(srcPath: String, dstPath: String): Unit = {
val hadoopConfig = new Configuration()
val hdfs = FileSystem.get(hadoopConfig)
FileUtil.copyMerge(hdfs, new Path(srcPath), hdfs, new Path(dstPath), true, hadoopConfig, null)
// the "true" setting deletes the source files once they are merged into the new output
}
Если вам не нужен заголовок, установите его в false, и вы не будете необходимо также выполнить объединение. Это будет быстрее написать тоже.
После того, как вы смоделировали схему, вы можете ссылаться на нее, используя «ref»
var subConfigsSchema = new Schema({
alias: String,
value: String,
position: Number
}, {_id: false});
var subConfigs = mongoose.model('SubConfig', subConfigsSchema);
var configsSchema = new Schema({
bfq: [subConfigsSchema],
qpa: [subConfigsSchema],
fmb: [subConfigsSchema],
cz: [subConfigsSchema]
}, {_id: false});
var config = mongoose.model('Config', ConfigsSchema);
var instrumentSchema = new Schema({
_id: {
type: Schema.Types.ObjectId,
ref: 'SubConfig',
required: true,
auto: true
},
configs: {
type: Schema.Types.ObjectId,
ref: 'Config',
required: true
}
},
{
strict: false,
versionKey: false
});
module.exports = mongoose.model('Instrument', instrumentSchema)
. Теперь при запросе вам нужно заполнить ссылочную модель ... Так что для этого вам нужно заполнить ссылочную модель. [113 ]
Instrument.find({}).populate('subconfig').populate('config').exec((err, data)=> {
if (err) throw err;
instrument = data[0];
console.log(instrument);
console.log(instrument._id);
console.log(instrument.inpname);
console.log(Instrument['inpname']);
});