⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rejectrecord.pm

📁 普通的ETL工具
💻 PM
字号:
# vim:ts=4 sw=4
# ----------------------------------------------------------------------------------------------------
#  Name		: ETL::Pequel3::Type::Section::RejectRecord.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::RejectRecord;
require 5.005_62;
use strict;
use warnings;
use ETL::Pequel3::Type::Section;
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::RejectRecord::Abstract;
	use base qw(ETL::Pequel3::Type::Section::Abstract);
	use Class::STL::ClassMembers
		qw( 
			reject_number 
			code_suffix
			reason_codes_list 
			dataset_spec
			output_dataset
			dataset 
		),
		Class::STL::ClassMembers::DataMember->new(name => 'target_mem_name', default => 'dataset_spec'),
		Class::STL::ClassMembers::DataMember->new(name => 'item_type', 
			default => 'ETL::Pequel3::Type::Section::RejectRecord::Item'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}");
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->reason_codes_list($self->pequel_ref()->catalogue()->fieldsets()->reject_reasons()->new(
			pequel_ref => $self->pequel_ref()))
		if (defined($self->pequel_ref()));
		$self->attributes()->push_back(
			ETL::Pequel3::Type::Properties::DataSetSpec->new(),
			$self->attributes()->factory(name => 'max_record_count'),
		);
	}
	sub prepare
	{
		my $self = shift;

		$self->err()->user_error(10250, "Reject (@{[ 
			$self->on() ]}) record section requires one or more condition statements!")
			unless ($self->items()->size());

		$self->reject_number($self->size()+1);
		$self->dataset($self->pequel_ref()->factories()->output_datasets()->factory( #TODO: output_dataset ?
			dataset_spec => $self->dataset_spec(), 
			pequel_ref => $self->pequel_ref()
		));

		$self->err()->trace_msg(10, "@{[ $self->pequel_ref()->pequel_name() ]} -->"
			. $self->section_name() . ':'
			. $self->dataset_spec()
			. "; Dataset-Fdname:" . $self->dataset()->datasource()->fdname()
		);
		foreach my $f ($self->items()->to_array()) 
		{
			$self->err()->user_error(10222, "Duplicate reason code '@{[ 
				$f->reason_code() ]}' not allowed!")
				if ($self->reason_codes_list()->exists($f->reason_code()));

			$self->reason_codes_list()->add(
				name => $f->reason_code(), 
				reason_code => $f->reason_code(), 
				condition_exp => $f->condition_exp(),
				reason_message => defined($f->reason_message()) ? $f->reason_message() : undef,
			);
			my $rf = $self->reason_codes_list()->back();
			my $suffix = $self->code_suffix() . $self->reject_number() . '_' . $rf->field_number();
			$rf->output_fields($self->pequel_ref()->catalogue()->fieldsets()->reject_fields()->new(
				pequel_ref => $self->pequel_ref()
			));
			$rf->output_fields()->add(
				name => "REASON_CODE_$suffix",  # TODO: reason_code_fieldname
				calc_exp => "'@{[ $f->reason_code() ]}'",
				dataset => $self->dataset(),
			);
			$rf->output_fields()->add(
				name => "REASON_MESSAGE_$suffix",  # TODO: reason_code_msgname
				calc_exp => "qq{@{[ $f->reason_message() ]}}",
				dataset => $self->dataset(),
			) if (defined($f->reason_message()));

			$self->err()->trace_msg(10, "@{[ $self->pequel_ref()->pequel_name() ]} -->"
				. "Reject Reason Code:" . $self->reason_codes_list()->back()->reason_code()
				. "Condition Expression:" . $self->reason_codes_list()->back()->condition_exp()
				. "Reason Message:" 
				. (defined($self->reason_codes_list()->back()->reason_message()) 
					? $self->reason_codes_list()->back()->reason_message() : 'NULL')
			);
		}
	}
	sub select
	{
		my $self = shift;
		my %p = @_;
		$self->err()->user_error(10211, "Section '@{[ 
			$self->section_name() ]}' select() function requires '@{[ $self->target_mem_name() ]}' parameter!")
			unless (exists($p{$self->target_mem_name()}));
		my $s;
		return $s if (($s = $self->exists($p{$self->target_mem_name()})) != 0);
		$self->add(%p);
		$self->back()->attributes()->set(@_);
		return $self->back();
	}

	package ETL::Pequel3::Type::Section::RejectRecord::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(
			$self->attributes()->factory(name => 'reason_code', required => 1),
			$self->attributes()->factory(name => 'condition_exp', required => 1),
			$self->attributes()->factory(name => 'reason_message'),
		);
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::RejectRecord;
	use base qw(ETL::Pequel3::Type::Section::RejectRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'reject_record'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => 'This section is used to specify a record I<rejection> action. Please refer to the specific F<reject_record_on_input> and F<reject_record_on_output> section type descriptions for detailed information.');
	use Class::STL::ClassMembers::Constructor;
	sub new_extra
	{
		my $self = shift;
		$self->attributes()->push_back(
			ETL::Pequel3::Type::Properties::On->new(),
		);
		return $self;
	}
	sub select
	{
		my $self = shift;
		my %p = @_;
		$self->err()->user_error(10211, "Section '@{[ 
			$self->section_name() ]}' select() function requires 'on' parameter!")
			unless (exists($p{on}));
		return $self->pequel_ref()->section("@{[ $self->section_name() ]}_on_@{[ lc($p{on}) ]}")->select(@_);
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::RejectRecordOnInput;
	use base qw(ETL::Pequel3::Type::Section::RejectRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'reject_record_on_input'),
		Class::STL::ClassMembers::DataMember->new(name => 'code_suffix', default => 'I'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record I<rejection> action. The input record will be I<diverted> to the distribution specified in the I<dataset_spec> property. The F<condition_exp> item attribute will determine if the record is rejected; if the record evaluates to true on the condition then the record is rejected.\n\n\nEach F<item> within a reject section contains a F<condition_exp> and an associated F<reason_code>, F<reason_message> -- these two fields will be appended to the rejected input record when diverted so as to identify the rejection reason.\n\n\nThe rejected records will not appear in the input processing.\n\n\nThe F<reject_record_on_input> action will take place right after the F<filter_on_input> and before the F<divert_record_on_input> actions.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.");
	use Class::STL::ClassMembers::Constructor;
	sub prepare
	{
		my $self = shift;
		$self->SUPER::prepare(@_);
		$self->dataset()->map_output(main => $self->pequel_ref(), on => 'input');
	}
	sub parse
	{
		my $self = shift;
		foreach my $r ($self->reason_codes_list()->to_array()) {
			$r->condition_exp_raw($self->pequel_ref()->parser_input()->translate($r->condition_exp())->raw());
			foreach my $f (grep(defined($_->calc_exp()), $r->output_fields()->to_array())) {
				$f->calc_exp_raw($self->pequel_ref()->parser_input()->translate($f->calc_exp())->raw());
			}
		}
	}
}
# ----------------------------------------------------------------------------------------------------
{
	package ETL::Pequel3::Type::Section::RejectRecordOnOutput;
	use base qw(ETL::Pequel3::Type::Section::RejectRecord::Abstract);
	use Class::STL::ClassMembers
		Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'reject_record_on_output'),
		Class::STL::ClassMembers::DataMember->new(name => 'code_suffix', default => 'O'),
		Class::STL::ClassMembers::DataMember->new(name => 'element_type', default => "@{[ __PACKAGE__ ]}"),
		Class::STL::ClassMembers::DataMember->new(name => 'description', default => "This section is used to specify a record I<rejection> action. The output record will be I<diverted> to the distribution specified in the I<dataset_spec> property. The F<condition_exp> item attribute will determine if the record is rejected; if the record evaluates to true on the condition then the record is rejected.\n\n\nEach F<item> within a reject section contains a F<condition_exp> and an associated F<reason_code>, F<reason_message> -- these two fields will be appended to the rejected output record when diverted so as to identify the rejection reason.\n\n\nThe rejected records will not appear in the output.\n\n\nThe F<reject_record_on_output> action will take place right after the F<field_process_on_output> and before the F<divert_record_on_output> actions.\n\n\nA I<pequel> object may contain multiple sections of this type, each one with a different F<dataset_spec> property.");
	use Class::STL::ClassMembers::Constructor;
	sub prepare
	{
		my $self = shift;
		$self->SUPER::prepare(@_);
		$self->dataset()->map_output(main => $self->pequel_ref(), on => 'output');
	}
	sub parse
	{
		my $self = shift;
		foreach my $r ($self->reason_codes_list()->to_array()) {
			$r->condition_exp_raw($self->pequel_ref()->parser_output()->translate($r->condition_exp())->raw());
			foreach my $f (grep(defined($_->calc_exp()), $r->output_fields()->to_array())) {
				$f->calc_exp_raw($self->pequel_ref()->parser_output()->translate($f->calc_exp())->raw());
			}
		}
	}
}
# ----------------------------------------------------------------------------------------------------
1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -