📄 table.pm
字号:
# vim:ts=4 sw=4
# ----------------------------------------------------------------------------------------------------
# Name : ETL::Pequel3::Type::Section::Table.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::Table;
require 5.005_62;
use strict;
use warnings;
use ETL::Pequel3::Type::Section;
# ----------------------------------------------------------------------------------------------------
{
package ETL::Pequel3::Type::Section::Table;
use base qw(ETL::Pequel3::Type::Section::Abstract);
use Class::STL::ClassMembers
qw(
table_name
table_ref
),
Class::STL::ClassMembers::DataMember->new(name => 'target_mem_name', default => 'table_name'),
Class::STL::ClassMembers::DataMember->new(name => 'section_name', default => 'table'),
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 => "Tables are a powerfull feature in F<pequel>. They provide functionality to access data from additional, secondary data streams. Table data is accessed via unique key lookup. The data for tables is pre-loaded at the start of the generated program execution, that is, before the main transformation process begins. Be aware that tables are memory intensive since the data is pre-loaded into memory -- it is up to the user to manage memory requirements.\n\n\nThe table consists of one or more rows consisting of key, value(s) pairs. Each row within the table will have a unique key. During table loading, only the first record for a key will be loaded.\n\n\nTables are global. All tables are loaded at the start of program execution. The same table name may be referenced across all sub and main pequel scripts.");
use Class::STL::ClassMembers::Constructor;
sub new_extra
{
my $self = shift;
$self->attributes()->push_back(
$self->attributes()->factory(name => 'table_name', required => 1),
ETL::Pequel3::Type::Properties::TableType->new(required => 1),
ETL::Pequel3::Type::Properties::DataSetSpec->new(required => 1),
$self->attributes()->factory(name => 'static'),
$self->attributes()->factory(name => 'key_field', required => 1),
$self->attributes()->factory(name => 'key_type'),
$self->attributes()->factory(name => 'field_map'), # =fname:col,fname:col,...
);
}
sub prepare
{
my $self = shift;
return if ($self->pequel_ref()->user_tables()->exists($self->table_name()));
$self->table_ref($self->pequel_ref()->user_tables()->factory(
name => $self->table_name(),
table_type => $self->attributes()->table_type(),
static => $self->attributes()->static(),
dataset_spec => $self->attributes()->dataset_spec(),
key_field => $self->attributes()->key_field(),
key_type => $self->attributes()->key_type(),
field_map => $self->attributes()->field_map(),
pequel_ref => $self->pequel_ref(),
));
$self->table_ref()->prepare($self->items());
$self->pequel_ref()->user_tables()->push_back($self->table_ref());
}
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 = $self->exists($p{$self->target_mem_name()});
return $s if (ref($s));
$self->add(%p);
$self->back()->attributes()->set(@_);
return $self->back();
}
package ETL::Pequel3::Type::Section::Table::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 => 'key_value'),
$self->attributes()->factory(name => 'data_values'),
);
}
}
# ----------------------------------------------------------------------------------------------------
1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -