Exemplo n.º 1
0
 public function lookup()
 {
     $inputs = [];
     foreach ($this->input as $name => $type) {
         $inputs[$name] = is_type($type) ? $type->lookup() : $type;
     }
     $outputs = [];
     foreach ($this->output as $name => $type) {
         $outputs[$name] = is_type($type) ? $type->lookup() : $type;
     }
     $sargs = [];
     foreach ($this->req_states() as $name => $type) {
         $sargs[$name] = $type->lookup();
     }
     return lookupGLA($this->name(), $this->template_args(), $inputs, $outputs, $sargs, null, $this->hash());
 }
Exemplo n.º 2
0
/**
 *  A GLA that counts the number of distinct elements by keeping track of the
 *  distinct elements.
 *
 *  Unless an exact count of the distinct is absolutely needed, consider using
 *  an approximation of the distinct, such as a Bloom Filter.
 */
function CountDistinct(array $t_args, array $input, array $output)
{
    grokit_assert(\count($output) == 1, 'CountDistinct should have only 1 output, ' . \count($output) . 'given');
    $outputName = array_keys($output)[0];
    $outputType = array_get_index($output, 0);
    if (is_null($outputType)) {
        $outputType = lookupType('BASE::BIGINT');
    }
    $output[$outputName] = $outputType;
    grokit_assert($outputType->is('numeric'), 'CountDistinct output must be numeric!');
    $useMCT = get_default($t_args, 'use.mct', true);
    $keepHashes = get_default($t_args, 'mct.keep.hashes', false);
    $initSize = get_default($t_args, 'init.size', 65536);
    $nullCheck = get_default($t_args, 'null.check', false);
    grokit_assert(is_bool($useMCT), 'CountDistinct use.mct argument must be boolean');
    grokit_assert(is_integer($initSize), 'Distinct init.size argument must be an integer');
    grokit_assert($initSize > 0, 'Distinct init.size argument must be positive');
    grokit_assert(is_bool($keepHashes), 'CountDistinct mct.keep.hashes argument must be boolean');
    $distTmpArgs = ['use.mct' => $useMCT, 'init.size' => $initSize, 'mct.keep.hashes' => $keepHashes, 'null.check' => $nullCheck];
    $gla = lookupGLA('BASE::DISTINCT', $distTmpArgs, $input, $input);
    $className = generate_name('CountDistinct');
    ?>
class <?php 
    echo $className;
    ?>
 {
    using Distinct = <?php 
    echo $gla->value();
    ?>
;

    Distinct distinctGLA;

public:

    <?php 
    echo $className;
    ?>
(void):
        distinctGLA()
    { }

    ~<?php 
    echo $className;
    ?>
(void) { }

    void AddItem(<?php 
    echo const_typed_ref_args($input);
    ?>
) {
        distinctGLA.AddItem(<?php 
    echo args($input);
    ?>
);
    }

    void AddState(<?php 
    echo $className;
    ?>
 & o) {
        distinctGLA.AddState(o.distinctGLA);
    }

    void GetResult(<?php 
    echo $outputType;
    ?>
 & <?php 
    echo $outputName;
    ?>
) {
        <?php 
    echo $outputName;
    ?>
 = distinctGLA.get_countDistinct();
    }
};
<?php 
    return ['kind' => 'GLA', 'name' => $className, 'input' => $input, 'output' => $output, 'result_type' => 'single'];
}
Exemplo n.º 3
0
 public function apply($inputs, $outputs, $sargs = [])
 {
     try {
         $input = [];
         foreach ($inputs as $n => $v) {
             if (is_datatype($v)) {
                 $input[$n] = $v;
             } else {
                 $input[$n] = $v->type();
             }
         }
         return lookupGLA($this->name, $this->t_args, $input, $outputs, $sargs, $this->alias);
     } catch (Exception $e) {
         grokit_error('Failed to lookup GLA ' . $this->name . ' from spec ' . $this->source, $e);
     }
 }