12
12
#include " schemaless_writer_adapter.h"
13
13
#include " skiff_parser.h"
14
14
#include " skiff_writer.h"
15
+ #include " yaml_parser.h"
16
+ #include " yaml_writer.h"
15
17
#include " yamred_dsv_parser.h"
16
18
#include " yamred_dsv_writer.h"
17
19
#include " yamr_parser.h"
@@ -108,6 +110,18 @@ std::unique_ptr<IFlushableYsonConsumer> CreateConsumerForDsv(
108
110
};
109
111
}
110
112
113
+ std::unique_ptr<IFlushableYsonConsumer> CreateConsumerForYaml (
114
+ EDataType dataType,
115
+ const IAttributeDictionary& attributes,
116
+ IZeroCopyOutput* output)
117
+ {
118
+ if (dataType != EDataType::Structured) {
119
+ THROW_ERROR_EXCEPTION (" YAML is supported only for structured data" );
120
+ }
121
+ auto config = ConvertTo<TYamlFormatConfigPtr>(&attributes);
122
+ return CreateYamlWriter (output, DataTypeToYsonType (dataType), config);
123
+ }
124
+
111
125
class TTableParserAdapter
112
126
: public IParser
113
127
{
@@ -161,6 +175,8 @@ std::unique_ptr<IFlushableYsonConsumer> CreateConsumerForFormat(
161
175
return CreateConsumerForJson (dataType, format.Attributes (), output);
162
176
case EFormatType::Dsv:
163
177
return CreateConsumerForDsv (dataType, format.Attributes (), output);
178
+ case EFormatType::Yaml:
179
+ return CreateConsumerForYaml (dataType, format.Attributes (), output);
164
180
default :
165
181
THROW_ERROR_EXCEPTION (" Unsupported output format %Qlv" ,
166
182
format.GetType ());
@@ -408,6 +424,21 @@ TYsonProducer CreateProducerForJson(
408
424
});
409
425
}
410
426
427
+ TYsonProducer CreateProducerForYaml (
428
+ EDataType dataType,
429
+ const IAttributeDictionary& attributes,
430
+ IInputStream* input)
431
+ {
432
+ if (dataType != EDataType::Structured) {
433
+ THROW_ERROR_EXCEPTION (" YAML is supported only for structured data" );
434
+ }
435
+ auto ysonType = DataTypeToYsonType (dataType);
436
+ auto config = ConvertTo<TYamlFormatConfigPtr>(&attributes);
437
+ return BIND ([=] (IYsonConsumer* consumer) {
438
+ ParseYaml (input, consumer, config, ysonType);
439
+ });
440
+ }
441
+
411
442
TYsonProducer CreateProducerForYson (EDataType dataType, IInputStream* input)
412
443
{
413
444
auto ysonType = DataTypeToYsonType (dataType);
@@ -429,6 +460,8 @@ TYsonProducer CreateProducerForFormat(const TFormat& format, EDataType dataType,
429
460
return CreateProducerForYamredDsv (dataType, format.Attributes (), input);
430
461
case EFormatType::SchemafulDsv:
431
462
return CreateProducerForSchemafulDsv (dataType, format.Attributes (), input);
463
+ case EFormatType::Yaml:
464
+ return CreateProducerForYaml (dataType, format.Attributes (), input);
432
465
default :
433
466
THROW_ERROR_EXCEPTION (" Unsupported input format %Qlv" ,
434
467
format.GetType ());
@@ -489,6 +522,10 @@ std::unique_ptr<IParser> CreateParserForFormat(const TFormat& format, EDataType
489
522
auto config = ConvertTo<TSchemafulDsvFormatConfigPtr>(&format.Attributes ());
490
523
return CreateParserForSchemafulDsv (consumer, config);
491
524
}
525
+ case EFormatType::Yaml:
526
+ // We can only get here with EDataType::Tabular, so throw specific error about supporting
527
+ // only structured data in YAML.
528
+ THROW_ERROR_EXCEPTION (" YAML is supported only for structured data" );
492
529
default :
493
530
THROW_ERROR_EXCEPTION (" Unsupported input format %Qlv" ,
494
531
format.GetType ());
0 commit comments