Skip to content
DataMiner DoJo

More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Search in posts
Search in pages
Search in posts
Search in pages
Log in
Menu
  • Updates & Insights
  • Questions
  • Learning
    • E-learning Courses
    • Empower Replay: Limited Edition
    • Tutorials
    • Open Classroom Training
    • Certification
      • DataMiner Fundamentals
      • DataMiner Configurator
      • DataMiner Automation
      • Scripts & Connectors Developer: HTTP Basics
      • Scripts & Connectors Developer: SNMP Basics
      • Visual Overview – Level 1
      • Verify a certificate
    • Video Library
    • Books We Like
    • >> Go to DataMiner Docs
  • Expert Center
    • Solutions & Use Cases
      • Solutions
      • Use Case Library
    • Markets & Industries
      • Media production
      • Government & defense
      • Content distribution
      • Service providers
      • Partners
      • OSS/BSS
    • Agile
      • Agile Webspace
      • Everything Agile
        • The Agile Manifesto
        • Best Practices
        • Retro Recipes
      • Methodologies
        • The Scrum Framework
        • Kanban
        • Extreme Programming
      • Roles
        • The Product Owner
        • The Agile Coach
        • The Quality & UX Coach (QX)
    • DataMiner DevOps Professional Program
      • About the DevOps Program
      • DataMiner DevOps Support
  • Downloads
  • More
    • DataMiner Releases & Updates
    • Feature Suggestions
    • Climb the leaderboard!
    • Swag Shop
    • Contact
    • Global Feedback Survey
  • PARTNERS
    • All Partners
    • Technology Partners
    • Strategic Partner Program
    • Deal Registration
  • >> Go to dataminer.services

GQI – Random Row from Source

Solved454 views14th June 2024GQI custom operator
0
Thomas Remmery [SLC] [DevOps Advocate]690 14th June 2024 0 Comments

Hi all,

I'm trying to create custom GQI operator that would remove all rows except a single, random one. I have a working example in which I'm using a random generator to determine which row I would like to keep. However, I need to know upfront how many rows there are in the source, so my random index doesn't go out of bounds. In my test version I'm providing that row count as an argument, which wouldn't make sense in a real situation.

Below is my code. If you feel like there is a better way to tackle this please let me know. Also, I don't want to go an create custom data source just for this use case.

Kind regards,

public class RandomRowOperator : IGQIRowOperator, IGQIInputArguments
{
private GQIIntArgument rowCountArgument = new GQIIntArgument("Row Count") { IsRequired = true };
private GQIIntArgument seedArgument = new GQIIntArgument("Seed") { IsRequired = false };

private int _rowIndex;

public GQIArgument[] GetInputArguments()
{
return new GQIArgument[] {
rowCountArgument,
seedArgument
};
}

public void HandleRow(GQIEditableRow row)
{
if (_rowIndex != 0)
{
row.Delete();
}

_rowIndex--;
}

public OnArgumentsProcessedOutputArgs OnArgumentsProcessed(OnArgumentsProcessedInputArgs args)
{
int rowCount = args.GetArgumentValue(rowCountArgument);

Random random;
if (args.HasArgumentValue(seedArgument))
{
int seed = args.GetArgumentValue(seedArgument);
random = new Random(seed);
}
else
{
random = new Random();
}

_rowIndex = random.Next(rowCount);

return new OnArgumentsProcessedOutputArgs();
}
}

Thomas Remmery [SLC] [DevOps Advocate] Selected answer as best 14th June 2024

1 Answer

  • Active
  • Voted
  • Newest
  • Oldest
2
Tom Waterbley [SLC] [DevOps Catalyst]8.89K Posted 14th June 2024 0 Comments

Hi Thomas,

To get rid of the input parameters, you could add an extra column with a random number in your custom operator. Then you could use that new column to sort and take the first row.

Thomas Remmery [SLC] [DevOps Advocate] Selected answer as best 14th June 2024
You are viewing 1 out of 1 answers, click here to view all answers.
Please login to be able to comment or post an answer.

My DevOps rank

DevOps Members get more insights on their profile page.

My user earnings

0 Dojo credits

Spend your credits in our swag shop.

0 Reputation points

Boost your reputation, climb the leaderboard.

Promo banner DataMiner DevOps Professiona Program
DataMiner Integration Studio (DIS)
Empower Katas
Privacy Policy • Terms & Conditions • Contact

© 2025 Skyline Communications. All rights reserved.

DOJO Q&A widget

Can't find what you need?

? Explore the Q&A DataMiner Docs

[ Placeholder content for popup link ] WordPress Download Manager - Best Download Management Plugin