Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8073825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:27:49+00:00 2026-06-05T14:27:49+00:00

Is there any standard / boilerplate way to convert SQL uniqueidentifiers into the same

  • 0

Is there any standard / boilerplate way to convert SQL uniqueidentifiers into the same HI/LO blocks as protobuf-net’s BCL.Guids?

UPDATE:

So, given a Guid, "4D1CE8BE-C36B-4FFA-A4C8-9056619E9967", ProtoBuf.NET will serialize it as {"lo":5763133538796628158,"hi":7465171998244653220,"___error___":null}, which is how it subsequently gets stored in Hadoop. So SQL server has a column with a Guid id, and Hadoop ends up having separate id.lo and id.hi values. What I need is a query to look up a record in Hadoop given the id from SQL server. The C# code below gives me the translated value I’m after, but it requires me to run an intermediate client app simply to split the Guid. What I want to be able to get the id.lo and id.hi directly from a SQL query, so I can drop them straight into a filter in a subsequent Hadoop Map-Reduce job:

static void TestGuidSplit() {
            // Protobuf.Net serializes the following Guid as:
            // {"lo":5763133538796628158,"hi":7465171998244653220,"___error___":null}
            Guid testGuid = new Guid("4D1CE8BE-C36B-4FFA-A4C8-9056619E9967");
            Tuple<long, long> loHi = LoHi(testGuid);
            Console.WriteLine("lo: {0}, Hi:{1}.", loHi.Item1,loHi.Item2);
            Console.ReadLine();
        }
        static Tuple<long, long> LoHi(Guid someGuid) {
            byte[] bytes = someGuid.ToByteArray();
            long[] longs = new long[2];
            longs[0] = BitConverter.ToInt64(bytes, 0); // [0] = 5763133538796628158 = lo
            longs[1] = BitConverter.ToInt64(bytes, 8); // [1] = 7465171998244653220 = hi
            return new Tuple<long, long>(longs[0], longs[1]);
        }

ORIGINAL QUESTION:

I have a ton of data in SQL Server that I need to join to data that was exported to Hadoop via protobuf-net. We have keys in common, but they are all uniqueidentifiers. With homogeneously-formatted keys, we could just extract a flat file from SQL, create a tabledef over that flat file in Hive, and then use Hive to run a joined query over that and the hadoop tables. With the disparate uuid formats though, this doesn’t seem possible.

Do we need an intermediate process to harmonize the uuid formats? I’m hoping there’s a way around this, i.e. to do it more like a simple ETL process. Ultimately, we just want to get at a set of hadoop data where some_id in (list of sql ids). The hadoop data is of unmanageable size if extracted without filtering down to the relevant ids from sql.

The simplest example I can think of to describe what I’m trying to do would be to imagine that I had two tables in SQL server, ‘a’ and ‘b’, where ‘a’ contained several uuid fields, and ‘b’ was a copy of ‘a’ except that the uuids were now 64-bit integers, HI/LO, from protobuf-net’s bcl.guid. Given that scenario, I want to select * from ‘b’ where someid in (select someid from ‘a’ where interesting = true). What I’m missing is a function to get the HI and/or LO of someid from ‘a’, to supply to the in clause for my query from ‘b’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:27:51+00:00Added an answer on June 5, 2026 at 2:27 pm

    Conversion in SQL from a SQL uniqueidentifier column to the same hi / lo values generated by protobuf-net:

    declare @guid uniqueidentifier = convert(uniqueidentifier, '4D1CE8BE-C36B-4FFA-A4C8-9056619E9967')
    select @guid as 'guid' -- writes: 4D1CE8BE-C36B-4FFA-A4C8-9056619E9967, to prove it parsed correctly
    declare @blob binary(16) = CONVERT(binary(16), @guid)
    select CAST(SUBSTRING(@blob, 8, 1) + SUBSTRING(@blob, 7, 1) + SUBSTRING(@blob, 6, 1) + SUBSTRING(@blob, 5, 1) +
           SUBSTRING(@blob, 4, 1) + SUBSTRING(@blob, 3, 1) + SUBSTRING(@blob, 2, 1) + SUBSTRING(@blob, 1, 1) as bigint) as 'lo',
           CAST(SUBSTRING(@blob, 16, 1) + SUBSTRING(@blob, 15, 1) + SUBSTRING(@blob, 14, 1) + SUBSTRING(@blob, 13, 1) +
           SUBSTRING(@blob, 12, 1) + SUBSTRING(@blob, 11, 1) + SUBSTRING(@blob, 10, 1) + SUBSTRING(@blob, 9, 1) as bigint) as 'hi'
           -- writes: 5763133538796628158, 7465171998244653220
    

    Note you can probably wrap this as a UDF somewhere…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any standard way to route all Key events from the control A
Is there any standard way of implementing some sort of a write-through buffer for
Is there any way to start foobar.js WSH-script in order that standard Task Manager
Is there any easy way to change the color of the UITableViewCellAccessoryCheckmark from standard
Is there any standard naming convention for VB.NET ? Based your programming experiences, would
Is there any standard way to work with application settings in WinAPI? What I'm
Is there any standard way of detecting when a user is away or not
Is there any standard way to create drop-down menu from QLineEdit without QCompleter? For
I was wondering if there any standard format to import/export brushes in .net. For
Is there any standard way to access Java Bean Property like class A {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.