Skip to content

Experimental index operators support#257

Closed
quanterion wants to merge 1 commit intonpgsql:devfrom
quanterion:index_operators
Closed

Experimental index operators support#257
quanterion wants to merge 1 commit intonpgsql:devfrom
quanterion:index_operators

Conversation

@quanterion
Copy link
Copy Markdown

Out of curiosity investigate a way to add index operators support.
It you would accept this functionality let me know how to work on this PR.
It could help to avoid fallback to raw SQL code migrations in cases like that #256

Copy link
Copy Markdown
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

@quanterion, congrats, this looks quite good - and it's great to receive a contribution which models PostgreSQL-specific features.

I've made a few comments to make this mergeable, take a look. In addition:

  • Please add tests which demonstrate this. See how IndexMethod is currently tested.
  • Add a documentation note under doc.
  • You could also look at scaffolding support, i.e. including the index operator annotations included in models generated with EF Core. This really is extra-credit and not absolutely required (although it's fun!).

public const string HiLoSequenceName = Prefix + "HiLoSequenceName";
public const string HiLoSequenceSchema = Prefix + "HiLoSequenceSchema";
public const string IndexMethod = Prefix + "IndexMethod";
public const string IndexOperators = Prefix + "IndexOperator";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be IndexOperators

protected virtual string[] GetOperators() {
var value = (string)Annotations.Metadata[NpgsqlAnnotationNames.IndexOperators];
if (value != null) {
return value.Split(' ');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For correctness, it would be good to surround each operator class with quotes and delimit (i.e. for the theoretical case where an operator class contains a space...). Take a look at how the metadata for PostgreSQL extensions is implemented.

Copy link
Copy Markdown
Author

@quanterion quanterion Nov 1, 2017

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah... I wouldn't really bother with extracting them to avoid duplication though.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i assume delimit happens during set.

var columnList = new List<string>();
for (var k = 0; k < operation.Columns.Count - 1; ++k) {
var columnWithOperator = ColumnList(operation.Columns[k]);
if (k < operatorList.Count) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should also be possible to have a null in the operator list to skip explicitly defining the operator class for the correspond column (leaving it at the default).

}
columnList.Add(columnWithOperator);
}
builder
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code is duplicated above, for the case where no operators are defined. Set up your column list (separately for each case), then render once.

Copy link
Copy Markdown
Author

@quanterion quanterion Nov 1, 2017

Choose a reason for hiding this comment

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

I can see in EF sources that ColumnList function transforms each column name and join them together. But I can't find a public function that transform each column name individually. That is why I use ColumnList to transform each column name in second case ( and that is not the optimal way) that is why I duplicated the code. What can you recommend me?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was just thinking about generating the contents inside the parentheses differently (based on the condition), and then having common code which appends the parentheses and the contents (nothing fancy).

@olivierr91
Copy link
Copy Markdown

@quanterion Do you plan to complete the feature?


protected virtual bool SetOperators(string[] operators) {
if (operators != null && operators.Count > 0) {
Annotations.SetAnnotation(NpgsqlAnnotationNames.IndexMethod, operators.Join(' '));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since an annotation can contain string array, there shouldn't be need to do a join here. Else it is causing inconsistency in the code that is the annotation value is string or string[]

@roji roji force-pushed the dev branch 3 times, most recently from f320396 to dfdc336 Compare February 27, 2018 15:43
@roji
Copy link
Copy Markdown
Member

roji commented Jun 22, 2018

@quanterion am going to close this PR as there hasn't been any activity in a long time. If you'd like to pick this up again please go ahead (and let us know), in the meantime #481 was opened to track this feature.

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.

4 participants