📄 output.pm
字号:
# vim:ts=4 sw=4
# ----------------------------------------------------------------------------------------------------
# Name : ETL::Pequel3::Type::Section::Output.pm
# Created : 22 June 2006
# Author : Mario Gaffiero (gaffie)
#
# Copyright 1999-2007 Mario Gaffiero.
#
# This file is part of Pequel(TM).
#
# Pequel is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# Pequel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pequel; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# ----------------------------------------------------------------------------------------------------
# Modification History
# When Version Who What
# ----------------------------------------------------------------------------------------------------
package ETL::Pequel3::Type::Section::Output;
require 5.005_62;
use strict;
use warnings;
use ETL::Pequel3::Type::Section;
# ----------------------------------------------------------------------------------------------------
{
package ETL::Pequel3::Type::Section::Output;
use base qw(ETL::Pequel3::Type::Section::Abstract);
use Class::STL::ClassMembers
qw(
output_dataset
output_fields
transfer_fields
transfer_dataset
),
Class::STL::ClassMembers::DataMember->new(name => 'target_mem_name', default => 'section_name'),
Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'output'),
Class::STL::ClassMembers::DataMember->new(name => 'item_type', default => __PACKAGE__ . '::Item'),
Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This is where the output data stream format and aggregation is specified. At least one output field must be defined here (unless the F<transfer> option is specified). The output field name can be the same as an input field name, unless the output field is a calculated field. Each output field name must be unique. This name will appear in the header record (if the F<header> option is set). There may only be a single F<output> section within a I<pequel> object.\n\n\nA prefix of C<_> in the output field name causes that field to be I<transparent>; transparent fields will not be output, their use is mainly for intermediate calculations.\n\n\nThe F<input_field_name> can be any field declared in the F<input> section, including derived input fields.\n\n\nB<Item Types>\n\nThere are three types of output I<item> specifications:\n\n\nB<Type #1>\n\nthe first type consists of F<pequel_type>, F<field_name> and F<input_field_name> -- this is the simplest type and is used to copy the specified I<input_field> value to the corresponding output field;\n\n\nB<Type #2>\n\nthe second type has the addition of F<aggregate_type> and, optionally, F<condition_exp> -- this type is used to create an aggregation;\n\n\nB<Type #3>\n\nthe third type consists of F<pequel_type>, F<field_name> and F<calc_expression> -- this last type is used to create a derived output field based on other output fields. Input fields may not be referenced in the I<calculation expression>.");
use Class::STL::ClassMembers::Constructor;
sub new_extra
{
my $self = shift;
$self->output_fields($self->pequel_ref()->catalogue()->fieldsets()->output_fields()->new(
pequel_ref => $self->pequel_ref()))
if (defined($self->pequel_ref()));
#NOTE: need to create this early because its referenced by input_join:
$self->transfer_fields($self->pequel_ref()->catalogue()->fieldsets()->transfer_fields()->new(
pequel_ref => $self->pequel_ref()))
if (defined($self->pequel_ref()));
$self->attributes()->push_back(
ETL::Pequel3::Type::Properties::DataSetSpec->new(),
);
return $self;
}
sub prepare
{
my $self = shift;
$self->err()->diag(25, "@{[ $self->section_name() ]}: dataset factory...");
$self->output_dataset($self->pequel_ref()->factories()->output_datasets()->factory(
dataset_spec => $self->attributes()->dataset_spec(),
pequel_ref => $self->pequel_ref()
)); #??? unless (defined($self->output_dataset()));
#NOTE: This needs to be done here because group_by_fields will not yet be
#available in Section::Input;
if ($self->pequel_ref()->config()->transfer())
{
$self->err()->diag(25, "@{[ $self->section_name() ]}: config transfer...");
$self->transfer_fields()->map_input_fields(
$self->pequel_ref()->input()->input_fields(),
$self->transfer_dataset($self->pequel_ref()->factories()->output_datasets()->factory(
dataset_spec => 'void',
fdname => '_O_TRANSFER',
pequel_ref => $self->pequel_ref()
)),
($self->pequel_ref()->user_sections()->group_by()->size()
? $self->pequel_ref()->config()->transfer() : 'last')
);
}
$self->output_fields()->dataset($self->output_dataset());
$self->output_fields()->clear();
$self->output_fields()->map_input($self->items(), $self->pequel_ref()->input()->input_fields());
$self->output_dataset()->map_output(main => $self->pequel_ref(), on => 'output');
$self->err()->user_error(10217, "One of 'output-section' or 'transfer' option is required in '@{[
$self->pequel_ref()->pequel_name() ]}'!")
unless
(
$self->pequel_ref()->isa('ETL::Pequel3::User::TableLoader')
|| $self->output_fields()->size()
|| $self->pequel_ref()->config()->transfer()
|| $self->transfer_fields()->size()
);
}
sub parse
{
my $self = shift;
foreach ($self->output_fields()->to_array())
{
$_->calc_exp_raw($self->pequel_ref()->parser_output()->used_by($_)->translate($_->calc_exp())->raw())
if (defined($_->calc_exp()));
$_->condition_exp_raw($self->pequel_ref()->parser_output()->used_by($_)->translate($_->condition_exp())->raw())
if (defined($_->condition_exp()));
}
}
package ETL::Pequel3::Type::Section::Output::Item;
use base qw(ETL::Pequel3::Type::Section::Item::Abstract);
use Class::STL::ClassMembers;
use Class::STL::ClassMembers::Constructor;
sub new_extra
{
my $self = shift;
$self->attributes()->push_back(
ETL::Pequel3::Type::Properties::PequelType->new(required => 1), #required=>'1|2|3'
ETL::Pequel3::Type::Properties::FieldName->new(required => 1), #required=>'1|2|3'
ETL::Pequel3::Type::Properties::AggregateType->new(), #required=>2
ETL::Pequel3::Type::Properties::FieldName->new(name => 'input_field_name'), #required=>'1|2'
$self->attributes()->factory(name => 'calc_exp'), #required=>3
$self->attributes()->factory(name => 'condition_exp'), #required=>'~2' -- means optional in type 2 only
ETL::Pequel3::Type::Properties::DateType->new(),
$self->attributes()->factory(name => 'xml_type', default => 'PCDATA', validate => '^(attr|PCDATA|CDATA)$'),
);
}
}
# ----------------------------------------------------------------------------------------------------
1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -