How can I use hook_views_query_alter()?
According to the documentation page for hook_views_query_alter(), this hook works in Drupal 8, but (as you can see in comments for the referenced article) you should place it in mymodule.views_execution.inc, not in mymodule.module.