blob: 26914a98acca853bab1a890d8b3ffb51cc521160 [file] [log] [blame]
<!DOCTYPE HTML>
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc -->
<title>ZOrderByteUtils</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
<script type="text/javascript" src="../../../../jquery/jszip/dist/jszip.min.js"></script>
<script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
<!--[if IE]>
<script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
<![endif]-->
<script type="text/javascript" src="../../../../jquery/jquery-3.5.1.js"></script>
<script type="text/javascript" src="../../../../jquery/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="ZOrderByteUtils";
}
}
catch(err) {
}
//-->
var data = {"i0":9,"i1":9,"i2":9,"i3":9,"i4":9,"i5":9,"i6":9,"i7":9,"i8":9};
var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
var pathtoroot = "../../../../";
var useModuleDirectories = true;
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<header role="banner">
<nav role="navigation">
<div class="fixedNav">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a id="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<ul class="navListSearch">
<li><label for="search">SEARCH:</label>
<input type="text" id="search" value="search" disabled="disabled">
<input type="reset" id="reset" value="reset" disabled="disabled">
</li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a id="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
</div>
<div class="navPadding">&nbsp;</div>
<script type="text/javascript"><!--
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));
//-->
</script>
</nav>
</header>
<!-- ======== START OF CLASS DATA ======== -->
<main role="main">
<div class="header">
<div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="package-summary.html">org.apache.iceberg.util</a></div>
<h2 title="Class ZOrderByteUtils" class="title">Class ZOrderByteUtils</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>org.apache.iceberg.util.ZOrderByteUtils</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<pre>public class <span class="typeNameLabel">ZOrderByteUtils</span>
extends java.lang.Object</pre>
<div class="block">Within Z-Ordering the byte representations of objects being compared must be ordered, this
requires several types to be transformed when converted to bytes. The goal is to map object's
whose byte representation are not lexicographically ordered into representations that are
lexicographically ordered. Bytes produced should be compared lexicographically as unsigned bytes,
big-endian.
<p>All types except for String are stored within an 8 Byte Buffer
<p>Most of these techniques are derived from
https://aws.amazon.com/blogs/database/z-order-indexing-for-multifaceted-queries-in-amazon-dynamodb-part-2/
<p>Some implementation is taken from
https://github.com/apache/hbase/blob/master/hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java</div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== FIELD SUMMARY =========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="field.summary">
<!-- -->
</a>
<h3>Field Summary</h3>
<table class="memberSummary">
<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Field</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#PRIMITIVE_BUFFER_SIZE">PRIMITIVE_BUFFER_SIZE</a></span></code></th>
<td class="colLast">&nbsp;</td>
</tr>
</table>
</li>
</ul>
</section>
<!-- ========== METHOD SUMMARY =========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Method</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#byteTruncateOrFill(byte%5B%5D,int,java.nio.ByteBuffer)">byteTruncateOrFill</a></span>&#8203;(byte[]&nbsp;val,
int&nbsp;length,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Return a bytebuffer with the given bytes truncated to length, or filled with 0's to length
depending on whether the given bytes are larger or smaller than the given length.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#doubleToOrderedBytes(double,java.nio.ByteBuffer)">doubleToOrderedBytes</a></span>&#8203;(double&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Doubles are treated the same as floats in <a href="#floatToOrderedBytes(float,java.nio.ByteBuffer)"><code>floatToOrderedBytes(float, ByteBuffer)</code></a></div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#floatToOrderedBytes(float,java.nio.ByteBuffer)">floatToOrderedBytes</a></span>&#8203;(float&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">IEEE 754 : “If two floating-point numbers in the same format are ordered (say, x &lt;
y), they are ordered the same way when their bits are reinterpreted as sign-magnitude
integers.”</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>static byte[]</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#interleaveBits(byte%5B%5D%5B%5D,int,java.nio.ByteBuffer)">interleaveBits</a></span>&#8203;(byte[][]&nbsp;columnsBinary,
int&nbsp;interleavedSize,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Interleave bits using a naive loop.</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#intToOrderedBytes(int,java.nio.ByteBuffer)">intToOrderedBytes</a></span>&#8203;(int&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Signed ints do not have their bytes in magnitude order because of the sign bit.</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#longToOrderedBytes(long,java.nio.ByteBuffer)">longToOrderedBytes</a></span>&#8203;(long&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Signed longs are treated the same as the signed ints in <a href="#intToOrderedBytes(int,java.nio.ByteBuffer)"><code>intToOrderedBytes(int,
ByteBuffer)</code></a></div>
</td>
</tr>
<tr id="i6" class="altColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#shortToOrderedBytes(short,java.nio.ByteBuffer)">shortToOrderedBytes</a></span>&#8203;(short&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Signed shorts are treated the same as the signed ints in <a href="#intToOrderedBytes(int,java.nio.ByteBuffer)"><code>intToOrderedBytes(int,
ByteBuffer)</code></a></div>
</td>
</tr>
<tr id="i7" class="rowColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#stringToOrderedBytes(java.lang.String,int,java.nio.ByteBuffer,java.nio.charset.CharsetEncoder)">stringToOrderedBytes</a></span>&#8203;(java.lang.String&nbsp;val,
int&nbsp;length,
java.nio.ByteBuffer&nbsp;reuse,
java.nio.charset.CharsetEncoder&nbsp;encoder)</code></th>
<td class="colLast">
<div class="block">Strings are lexicographically sortable BUT if different byte array lengths will ruin the
Z-Ordering.</div>
</td>
</tr>
<tr id="i8" class="altColor">
<td class="colFirst"><code>static java.nio.ByteBuffer</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#tinyintToOrderedBytes(byte,java.nio.ByteBuffer)">tinyintToOrderedBytes</a></span>&#8203;(byte&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</code></th>
<td class="colLast">
<div class="block">Signed tiny ints are treated the same as the signed ints in <a href="#intToOrderedBytes(int,java.nio.ByteBuffer)"><code>intToOrderedBytes(int,
ByteBuffer)</code></a></div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a id="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ FIELD DETAIL =========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="field.detail">
<!-- -->
</a>
<h3>Field Detail</h3>
<a id="PRIMITIVE_BUFFER_SIZE">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>PRIMITIVE_BUFFER_SIZE</h4>
<pre>public static final&nbsp;int PRIMITIVE_BUFFER_SIZE</pre>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../constant-values.html#org.apache.iceberg.util.ZOrderByteUtils.PRIMITIVE_BUFFER_SIZE">Constant Field Values</a></dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<!-- ============ METHOD DETAIL ========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a id="intToOrderedBytes(int,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>intToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;intToOrderedBytes&#8203;(int&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Signed ints do not have their bytes in magnitude order because of the sign bit. To fix this,
flip the sign bit so that all negatives are ordered before positives. This essentially shifts
the 0 value so that we don't break our ordering when we cross the new 0 value.</div>
</li>
</ul>
<a id="longToOrderedBytes(long,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>longToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;longToOrderedBytes&#8203;(long&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Signed longs are treated the same as the signed ints in <a href="#intToOrderedBytes(int,java.nio.ByteBuffer)"><code>intToOrderedBytes(int,
ByteBuffer)</code></a></div>
</li>
</ul>
<a id="shortToOrderedBytes(short,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>shortToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;shortToOrderedBytes&#8203;(short&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Signed shorts are treated the same as the signed ints in <a href="#intToOrderedBytes(int,java.nio.ByteBuffer)"><code>intToOrderedBytes(int,
ByteBuffer)</code></a></div>
</li>
</ul>
<a id="tinyintToOrderedBytes(byte,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>tinyintToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;tinyintToOrderedBytes&#8203;(byte&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Signed tiny ints are treated the same as the signed ints in <a href="#intToOrderedBytes(int,java.nio.ByteBuffer)"><code>intToOrderedBytes(int,
ByteBuffer)</code></a></div>
</li>
</ul>
<a id="floatToOrderedBytes(float,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>floatToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;floatToOrderedBytes&#8203;(float&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">IEEE 754 : “If two floating-point numbers in the same format are ordered (say, x &lt;
y), they are ordered the same way when their bits are reinterpreted as sign-magnitude
integers.”
<p>Which means floats can be treated as sign magnitude integers which can then be converted
into lexicographically comparable bytes</div>
</li>
</ul>
<a id="doubleToOrderedBytes(double,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>doubleToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;doubleToOrderedBytes&#8203;(double&nbsp;val,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Doubles are treated the same as floats in <a href="#floatToOrderedBytes(float,java.nio.ByteBuffer)"><code>floatToOrderedBytes(float, ByteBuffer)</code></a></div>
</li>
</ul>
<a id="stringToOrderedBytes(java.lang.String,int,java.nio.ByteBuffer,java.nio.charset.CharsetEncoder)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>stringToOrderedBytes</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;stringToOrderedBytes&#8203;(java.lang.String&nbsp;val,
int&nbsp;length,
java.nio.ByteBuffer&nbsp;reuse,
java.nio.charset.CharsetEncoder&nbsp;encoder)</pre>
<div class="block">Strings are lexicographically sortable BUT if different byte array lengths will ruin the
Z-Ordering. (ZOrder requires that a given column contribute the same number of bytes every
time). This implementation just uses a set size to for all output byte representations.
Truncating longer strings and right padding 0 for shorter strings.</div>
</li>
</ul>
<a id="byteTruncateOrFill(byte[],int,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>byteTruncateOrFill</h4>
<pre class="methodSignature">public static&nbsp;java.nio.ByteBuffer&nbsp;byteTruncateOrFill&#8203;(byte[]&nbsp;val,
int&nbsp;length,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Return a bytebuffer with the given bytes truncated to length, or filled with 0's to length
depending on whether the given bytes are larger or smaller than the given length.</div>
</li>
</ul>
<a id="interleaveBits(byte[][],int,java.nio.ByteBuffer)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>interleaveBits</h4>
<pre class="methodSignature">public static&nbsp;byte[]&nbsp;interleaveBits&#8203;(byte[][]&nbsp;columnsBinary,
int&nbsp;interleavedSize,
java.nio.ByteBuffer&nbsp;reuse)</pre>
<div class="block">Interleave bits using a naive loop. Variable length inputs are allowed but to get a consistent
ordering it is required that every column contribute the same number of bytes in each
invocation. Bits are interleaved from all columns that have a bit available at that position.
Once a Column has no more bits to produce it is skipped in the interleaving.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>columnsBinary</code> - an array of ordered byte representations of the columns being ZOrdered</dd>
<dd><code>interleavedSize</code> - the number of bytes to use in the output</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the columnbytes interleaved</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
</div>
</main>
<!-- ========= END OF CLASS DATA ========= -->
<footer role="contentinfo">
<nav role="navigation">
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a id="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a id="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</nav>
</footer>
</body>
</html>