MCPcopy Create free account
hub / github.com/apache/cloudberry / fixedwidth_out

Function fixedwidth_out

contrib/formatter_fixedwidth/fixedwidth.c:554–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

552
553
554Datum
555fixedwidth_out(PG_FUNCTION_ARGS)
556{
557 TupleDesc tupdesc;
558 MemoryContext m, oldcontext;
559 int ncolumns = 0;
560 format_t *myData;
561 char *data;
562 int datlen = 0;
563 ListCell *curIdx;
564 ListCell *curSize;
565 int field_size;
566 char *mapped_val;
567 char *mapped_val_with_blanks;
568 bool isnull;
569 Datum value;
570 int idx;
571 static FormatConfig format_out_config;
572
573 /* Must be called via the external table format manager */
574 if (!CALLED_AS_FORMATTER(fcinfo))
575 ereport(ERROR,
576 (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
577 errmsg("fixedwidth_out: not called by format manager")));
578
579 tupdesc = FORMATTER_GET_TUPDESC(fcinfo);
580 get_tuple_info(tupdesc, &ncolumns, &myData, &data, fcinfo, &format_out_config);
581
582 /* =======================================================================
583 * MAIN FORMATTING CODE
584 * ======================================================================= */
585 m = FORMATTER_GET_PER_ROW_MEM_CTX(fcinfo);
586 oldcontext = MemoryContextSwitchTo(m);
587
588 forboth(curIdx, format_out_config.fldIndexes, curSize, format_out_config.fldSizes)
589 {
590 field_size = lfirst_int(curSize);
591 idx = lfirst_int(curIdx) - 1;
592 isnull = myData->nulls[idx];
593 value = myData->values[idx];
594
595 if ( isnull )
596 {
597 mapped_val_with_blanks = make_val_with_blanks(fcinfo, format_out_config.null_value, field_size, &(myData->one_field));
598 }
599 else
600 {
601 mapped_val = OutputFunctionCall(&format_out_config.conv_functions[idx], value);
602 mapped_val_with_blanks = make_val_with_blanks(fcinfo, mapped_val, field_size, &(myData->one_field));
603 }
604
605 memcpy(&data[datlen], mapped_val_with_blanks, field_size);
606 datlen += field_size;
607 }
608
609 memcpy(&data[datlen], format_out_config.line_delimiter, format_out_config.line_delimiter_length);
610 datlen += format_out_config.line_delimiter_length;
611

Callers

nothing calls this directly

Calls 7

get_tuple_infoFunction · 0.85
MemoryContextSwitchToFunction · 0.85
forbothFunction · 0.85
make_val_with_blanksFunction · 0.85
OutputFunctionCallFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected