<commit_before><?php
namespace Vda\Query;

use Vda\Query\Operator\Operator;
use Vda\Util\BeanUtil;
use Vda\Util\Type;

class Insert implements IQueryPart
{
    /**
     * @var Table
     */
    private $table;

    /**
     * @var Field[]
     */
    private $fields = array();
    private $values = array();
    private $select;

    public static function insert()
    {
        return new self();
    }

    public function into(Table $table)
    {
        $this->table = $table;

        return $this;
    }

    public function fields()
    {
        $this->fields = func_get_args();

        return $this;
    }

    public function values()
    {
        $this->values = array();

        foreach (func_get_args() as $i => $value) {
            if (isset($this->fields[$i])) {
                $type = $this->fields[$i]->getType();
            } else {
                $type = Type::AUTO;
            }

            $this->values[$i] = $this->normalize($value, $type);
        }

        return $this;
    }

    public function set(Field $field, $value)
    {
        $this->fields[] = $field;
        $this->values[] = $this->normalize($value, $field->getType());

        return $this;
    }

    public function populate($bean)
    {
        $map = BeanUtil::toArray($bean);

        foreach ($this->table->getFields() as $f) {
            $propName = $f->getPropertyName();
            if (array_key_exists($propName, $map)) {
                $this->set($f, $map[$propName]);
            }
        }

        return $this;
    }


    public function select(Select $select)
    {
        $this->select = $select;

        return $this;
    }

    public function hasFields()
    {
        return !empty($this->fields);
    }

    public function isFromSelect()
    {
        return !empty($this->select);
    }

    public function getTable()
    {
        return $this->table;
    }

    public function getFields()
    {
        return $this->fields;
    }

    public function getValues()
    {
        return $this->values;
    }

    public function getSelect()
    {
        return $this->select;
    }

    public function onProcess(IQueryProcessor $processor)
    {
        $processor->processInsertQuery($this);
    }

    private function normalize($value, $type)
    {
        if (!$value instanceof IExpression) {
            return Operator::constant($value, $type);
        }

        return $value;
    }
}
<commit_msg>Insert: consider previously specified field list when populating from bean<commit_after><?php
namespace Vda\Query;

use Vda\Query\Operator\Operator;
use Vda\Util\BeanUtil;
use Vda\Util\Type;

class Insert implements IQueryPart
{
    /**
     * @var Table
     */
    private $table;

    /**
     * @var Field[]
     */
    private $fields = array();
    private $values = array();
    private $select;

    public static function insert()
    {
        return new self();
    }

    public function into(Table $table)
    {
        $this->table = $table;

        return $this;
    }

    public function fields()
    {
        $this->fields = func_get_args();

        return $this;
    }

    public function values()
    {
        $this->values = array();

        foreach (func_get_args() as $i => $value) {
            if (isset($this->fields[$i])) {
                $type = $this->fields[$i]->getType();
            } else {
                $type = Type::AUTO;
            }

            $this->values[$i] = $this->normalize($value, $type);
        }

        return $this;
    }

    public function set(Field $field, $value)
    {
        $this->fields[] = $field;
        $this->values[] = $this->normalize($value, $field->getType());

        return $this;
    }

    public function populate($bean)
    {
        $map = BeanUtil::toArray($bean);

        $fields = $this->fields ? : $this->table->getFields();

        foreach ($fields as $f) {
            $propName = $f->getPropertyName();
            if (array_key_exists($propName, $map)) {
                $this->set($f, $map[$propName]);
            }
        }

        return $this;
    }

    public function select(Select $select)
    {
        $this->select = $select;

        return $this;
    }

    public function hasFields()
    {
        return !empty($this->fields);
    }

    public function isFromSelect()
    {
        return !empty($this->select);
    }

    public function getTable()
    {
        return $this->table;
    }

    public function getFields()
    {
        return $this->fields;
    }

    public function getValues()
    {
        return $this->values;
    }

    public function getSelect()
    {
        return $this->select;
    }

    public function onProcess(IQueryProcessor $processor)
    {
        $processor->processInsertQuery($this);
    }

    private function normalize($value, $type)
    {
        if (!$value instanceof IExpression) {
            return Operator::constant($value, $type);
        }

        return $value;
    }
}

{'fraction_non_alphanumeric': 0.14091273018414732, 'fraction_numerical': 0.0, 'mean_word_length': 1.8057271195957327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7170278', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1446, 'n_words': 326}