Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/nex 136/configure spanner #636

Conversation

julien-sebire
Copy link
Member

@julien-sebire julien-sebire commented Jun 13, 2019

This requires PR oat-sa/lib-generis-search#21 and release of lib-generis-search.

This adds NewSql schema support.

jbout and others added 23 commits June 6, 2019 11:21
…nto feature/NEX-136/configure-spanner

# Conflicts:
#	manifest.php
#	scripts/update/Updater.php
…ments' into feature/NEX-136/configure-spanner
@codeclimate
Copy link

codeclimate bot commented Jun 17, 2019

Code Climate has analyzed commit ee36b3b and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

Copy link
Contributor

@jbout jbout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be merged as it is.
Some of the changes would be mergable already, but it would require a split into multiple PRs.

@ferenckiss89
Copy link
Contributor

ferenckiss89 commented Jun 20, 2019

Should not be merged as it is.
Some of the changes would be mergable already, but it would require a split into multiple PRs.

Please do not consider this comment for now.

/**
* @inheritdoc
*/
public function prepareStatement($modelId, $subject, $predicate, $object, $lang, $author)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method prepareStatement has 6 arguments (exceeds 4 allowed). Consider refactoring.

* @param string $author
* @return array
*/
abstract public function prepareStatement($modelId, $subject, $predicate, $object, $lang, $author);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method prepareStatement has 6 arguments (exceeds 4 allowed). Consider refactoring.

@julien-sebire julien-sebire changed the base branch from develop to feature/NEX-336/newsql-schema October 16, 2019 08:25
'predicate' => $predicate,
'object' => $object,
'l_language' => $lang,
'author' => is_null($author) ? '' : $author,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible please use $author ??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 7.1 rulez! (at last)... ;-)

{
$models = array_map(
function ($a) {
return "'" . $a . "'";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use cast (string) instead of the concatenation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where adding the quotes, in fact. $a is supposed to be a string already.

public function createModelsTable(Schema $schema)
{
$table = $schema->createTable('models');
$table->addColumn('modelid', 'string', ['length' => 23, 'notnull' => true]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't forget about the length of 36 for the uuid4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right! Thanks for reminder.

public function createStatementsTable(Schema $schema)
{
$table = $schema->createTable('statements');
$table->addColumn('id', 'string', ['length' => 23, 'notnull' => true]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here 36 chr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

{
$this->dbWrapper->insert('models', ['modeluri' => $namespace]);
$result = $this->dbWrapper->query('select modelid from models where modeluri = ?', [$namespace]);
return $result->fetch()['modelid'];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the fetch will not return an array that will contain the modelid index this will create a notice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Fixed by adding a test for the previous insert, also in NewSqlRdsModelFactory.

//TODO bad way, need to find better
$modelId = $this->getModelId($namespace);
if ($modelId === false) {
common_Logger::d('modelId not found, need to add namespace ' . $namespace);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the LoggerAwareTrait and the function from inside that instead of this singleton old logger

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

)
);

if (intval($result->fetchColumn()) > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casting to int will optimize your condition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public function getIteratorQuery($modelIds)
{
return 'SELECT * FROM statements '
. (is_null($modelIds) ? '' : 'WHERE ' . $this->buildModelSqlCondition($modelIds) . ' ')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think you need the is_null, also i think a sprintf will be more readable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

private static $instance = null;
public static function singleton()
{
$returnValue = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally

    if (self::$instance == null)
    {
      self::$instance = new Singleton();
    }
 
    return self::$instance;

but your implementation is different, can you please comment on the value of this form

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not my implementation. I just moved it from the bottom of the same file. But I'll remove this change, I don't want to be anywhere in seeming like writing a singleton method! :D

*/
public function getUniquePrimaryKey()
{
return strrev(uniqid('', true));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will modify this with uuid, no ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we do.

Copy link
Member Author

@julien-sebire julien-sebire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR.

'predicate' => $predicate,
'object' => $object,
'l_language' => $lang,
'author' => is_null($author) ? '' : $author,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 7.1 rulez! (at last)... ;-)

{
$models = array_map(
function ($a) {
return "'" . $a . "'";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where adding the quotes, in fact. $a is supposed to be a string already.

public function createModelsTable(Schema $schema)
{
$table = $schema->createTable('models');
$table->addColumn('modelid', 'string', ['length' => 23, 'notnull' => true]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, right! Thanks for reminder.

public function createStatementsTable(Schema $schema)
{
$table = $schema->createTable('statements');
$table->addColumn('id', 'string', ['length' => 23, 'notnull' => true]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

{
$this->dbWrapper->insert('models', ['modeluri' => $namespace]);
$result = $this->dbWrapper->query('select modelid from models where modeluri = ?', [$namespace]);
return $result->fetch()['modelid'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Fixed by adding a test for the previous insert, also in NewSqlRdsModelFactory.

//TODO bad way, need to find better
$modelId = $this->getModelId($namespace);
if ($modelId === false) {
common_Logger::d('modelId not found, need to add namespace ' . $namespace);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

)
);

if (intval($result->fetchColumn()) > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

public function getIteratorQuery($modelIds)
{
return 'SELECT * FROM statements '
. (is_null($modelIds) ? '' : 'WHERE ' . $this->buildModelSqlCondition($modelIds) . ' ')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

private static $instance = null;
public static function singleton()
{
$returnValue = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not my implementation. I just moved it from the bottom of the same file. But I'll remove this change, I don't want to be anywhere in seeming like writing a singleton method! :D

*/
public function getUniquePrimaryKey()
{
return strrev(uniqid('', true));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we do.

\core_kernel_persistence_smoothsql_SmoothModel::OPTION_READABLE_MODELS => array('1'),
\core_kernel_persistence_smoothsql_SmoothModel::OPTION_WRITEABLE_MODELS => array('1'),
\core_kernel_persistence_smoothsql_SmoothModel::OPTION_NEW_TRIPLE_MODEL => '1',
\core_kernel_persistence_smoothsql_SmoothModel::OPTION_READABLE_MODELS => [$writableModelId],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julien-sebire
Copy link
Member Author

This PR is split into:
#690
#692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants