mirror of https://github.com/apache/cassandra
merge from 1.0
git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@1196959 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
commit
2e024c8414
|
|
@ -10,9 +10,13 @@
|
|||
* Cache for CompressionMetadata objects (CASSANDRA-3427)
|
||||
* synchronize BiMap of bootstrapping tokens (CASSANDRA-3417)
|
||||
* Avoid large array allocation for compressed chunk offsets (CASSANDRA-3432)
|
||||
* fix DecimalType bytebuffer marshalling (CASSANDRA-3421)
|
||||
* fix bug that caused first column in per row indexes to be ignored
|
||||
(CASSANDRA-3441)
|
||||
Merged from 0.8:
|
||||
* acquire compactionlock during truncate (CASSANDRA-3399)
|
||||
* fix bug that caused first column in per row indexes to be ignored (CASSANDRA-3441)
|
||||
* fix displaying cfdef entries for super columnfamilies (CASSANDRA-3415)
|
||||
|
||||
|
||||
1.0.1
|
||||
* acquire references during index build to prevent delete problems
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ JVM_OPTS="$JVM_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
|
|||
|
||||
# GC logging options -- uncomment to enable
|
||||
# JVM_OPTS="$JVM_OPTS -XX:+PrintGCDetails"
|
||||
# JVM_OPTS="$JVM_OPTS -XX:+PrintGCTimeStamps"
|
||||
# JVM_OPTS="$JVM_OPTS -XX:+PrintGCDateStamps"
|
||||
# JVM_OPTS="$JVM_OPTS -XX:+PrintHeapAtGC"
|
||||
# JVM_OPTS="$JVM_OPTS -XX:+PrintTenuringDistribution"
|
||||
# JVM_OPTS="$JVM_OPTS -XX:+PrintGCApplicationStoppedTime"
|
||||
|
|
|
|||
|
|
@ -1740,9 +1740,9 @@ public class CliClient
|
|||
{
|
||||
sb.append(NEWLINE + TAB + TAB + "{");
|
||||
|
||||
final AbstractType comparator = getFormatType((cfDef.column_type == "Super")
|
||||
? cfDef.subcomparator_type
|
||||
: cfDef.comparator_type);
|
||||
final AbstractType comparator = getFormatType(cfDef.column_type.equals("Super")
|
||||
? cfDef.subcomparator_type
|
||||
: cfDef.comparator_type);
|
||||
sb.append("column_name : '" + CliUtils.escapeSQLString(comparator.getString(colDef.name)) + "'," + NEWLINE);
|
||||
String validationClass = normaliseType(colDef.validation_class, "org.apache.cassandra.db.marshal");
|
||||
sb.append(TAB + TAB + "validation_class : " + CliUtils.escapeSQLString(validationClass));
|
||||
|
|
|
|||
|
|
@ -86,12 +86,14 @@ public class JdbcDecimal extends AbstractJdbcType<BigDecimal>
|
|||
public BigDecimal compose(ByteBuffer bytes)
|
||||
{
|
||||
if (bytes == null) return null;
|
||||
|
||||
|
||||
// do not consume the contents of the ByteBuffer
|
||||
bytes = bytes.duplicate();
|
||||
int scale = bytes.getInt();
|
||||
byte[] bibytes = new byte[bytes.remaining()];
|
||||
bytes.get(bibytes, 0, bytes.remaining());
|
||||
bytes.get(bibytes);
|
||||
|
||||
BigInteger bi = new BigInteger(bibytes);
|
||||
|
||||
return new BigDecimal(bi,scale);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,15 @@ public class DecimalType extends AbstractType<BigDecimal>
|
|||
|
||||
public int compare(ByteBuffer bb0, ByteBuffer bb1)
|
||||
{
|
||||
if (bb0.remaining() == 0)
|
||||
{
|
||||
return bb1.remaining() == 0 ? 0 : -1;
|
||||
}
|
||||
if (bb1.remaining() == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return compose(bb0).compareTo(compose(bb1));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cassandra.db.marshal;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.cassandra.db.marshal.DecimalType;
|
||||
import org.apache.cassandra.utils.ByteBufferUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DecimalTypeTest
|
||||
{
|
||||
private static final String LOW = "12.34";
|
||||
private static final String HIGH = "34.5678";
|
||||
|
||||
private static BigDecimal zero = new BigDecimal("0.0");
|
||||
private static BigDecimal minus = new BigDecimal("-1.000001");
|
||||
private static BigDecimal low = new BigDecimal(LOW);
|
||||
private static BigDecimal high = new BigDecimal(HIGH);
|
||||
|
||||
@Test
|
||||
public void test1Decompose_compose()
|
||||
{
|
||||
ByteBuffer bb = DecimalType.instance.decompose(low);
|
||||
|
||||
String string = DecimalType.instance.compose(bb).toPlainString();
|
||||
|
||||
// check that the decomposed buffer when re-composed is equal to the initial string.
|
||||
assertEquals(LOW, string);
|
||||
|
||||
// check that a null argument yields an empty byte buffer
|
||||
bb = DecimalType.instance.decompose(null);
|
||||
assertEquals(bb, ByteBufferUtil.EMPTY_BYTE_BUFFER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2Compare()
|
||||
{
|
||||
ByteBuffer lowBB = DecimalType.instance.decompose(low);
|
||||
ByteBuffer low2BB = DecimalType.instance.decompose(low);
|
||||
ByteBuffer highBB = DecimalType.instance.decompose(high);
|
||||
assertEquals(-1, DecimalType.instance.compare(lowBB, highBB));
|
||||
|
||||
lowBB = DecimalType.instance.decompose(low);
|
||||
highBB = DecimalType.instance.decompose(high);
|
||||
assertEquals(1, DecimalType.instance.compare(highBB, lowBB));
|
||||
|
||||
lowBB = DecimalType.instance.decompose(low);
|
||||
assertEquals(0, DecimalType.instance.compare(low2BB, lowBB));
|
||||
|
||||
lowBB = DecimalType.instance.decompose(low);
|
||||
assertEquals(-1, DecimalType.instance.compare(ByteBufferUtil.EMPTY_BYTE_BUFFER, lowBB));
|
||||
|
||||
lowBB = DecimalType.instance.decompose(low);
|
||||
assertEquals(1, DecimalType.instance.compare(lowBB,ByteBufferUtil.EMPTY_BYTE_BUFFER));
|
||||
|
||||
assertEquals(0, DecimalType.instance.compare(ByteBufferUtil.EMPTY_BYTE_BUFFER,ByteBufferUtil.EMPTY_BYTE_BUFFER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3Sort()
|
||||
{
|
||||
ByteBuffer zeroBB = DecimalType.instance.decompose(zero);
|
||||
ByteBuffer minusBB = DecimalType.instance.decompose(minus);
|
||||
ByteBuffer lowBB = DecimalType.instance.decompose(low);
|
||||
ByteBuffer highBB = DecimalType.instance.decompose(high);
|
||||
|
||||
ByteBuffer[] array = {highBB,minusBB,lowBB,lowBB,zeroBB,minusBB};
|
||||
|
||||
// Sort the array of ByteBuffer using a DecimalType comparator
|
||||
Arrays.sort(array, DecimalType.instance);
|
||||
|
||||
// Check that the array is in order
|
||||
for (int i = 1; i < array.length; i++)
|
||||
{
|
||||
BigDecimal i0 = DecimalType.instance.compose(array[i - 1]);
|
||||
BigDecimal i1 = DecimalType.instance.compose(array[i]);
|
||||
assertTrue("#" + i, i0.compareTo(i1) <= 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue